trouble with connection to a db

  • Thread starter Thread starter Claudia Fong
  • Start date Start date
C

Claudia Fong

Hi,

I'm trying to connect to a sql db with my C# applciation but I'm having
trouble to connect..
It said - Error accessing the database: Cannot open database "LibDB"
requested by the login. The login failed.
but I didn't create any username and password, so I don't know how to
solve the problem? Can someone help me? It's my first time trying to
connnect to a sql database.

Here's my code:

SqlConnection cnn1 = new SqlConnection();

cnn1.ConnectionString = "Integrated Security=SSPI;" +
"Initial Catalog=LibDB;" +
"Data Source= .\\SQLExpress";

try
{
//open connection
cnn1.Open();
Console.WriteLine("Connection Suceeded");

//open connection
cnn1.Close();
Console.WriteLine("Connection Closed");
}
catch(Exception e)
{
Console.WriteLine("Error accessing the database: " +
e.Message);
}


Cheers!

Claudi
 
If I remove it, it seems fine.. but does that mean that I don't need to
tell the system the name of the db?

Connection Suceeded
Connection Closed

Cheers!

Claudi
 
Claudia Fong said:
Hi,

I'm trying to connect to a sql db with my C# applciation but I'm having
trouble to connect..
It said - Error accessing the database: Cannot open database "LibDB"
requested by the login. The login failed.
but I didn't create any username and password, so I don't know how to
solve the problem? Can someone help me? It's my first time trying to
connnect to a sql database.

Here's my code:

SqlConnection cnn1 = new SqlConnection();

cnn1.ConnectionString = "Integrated Security=SSPI;" +
"Initial Catalog=LibDB;" +
"Data Source= .\\SQLExpress";

try
{
//open connection
cnn1.Open();
Console.WriteLine("Connection Suceeded");

//open connection
cnn1.Close();
Console.WriteLine("Connection Closed");
}
catch(Exception e)
{
Console.WriteLine("Error accessing the database: " +
e.Message);
}


Cheers!

Claudi



If it's the first time you are trying to connect, how comes that you have a user DB called
LibDB? How did you create that DB without connecting to SQL?

Willy.
 
Claudia said:
I created the db inside the VS 2005..

Cheers!

Claudi

Then you get a connection to the database in the server explorer window,
right?

Right click on that connection and choose Properties, there you can see
what connection string VS uses.
 
Claudia Fong said:
I created the db inside the VS 2005..

Cheers!

Claudi


Ok, that means you did add a "Dataconnection" from within VS, so it should be possible to
use VS to inspect the connection properties and take them over in your ConnectionString.

Willy.
 
Hi,

plz,check out ur connection string once again.
I think the problem might be Integrated security=true/sspi;
b'coz in ur sql server u may have sql authentication.
check this first.

Regards
Kannan.P
 
Back
Top