|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
trouble with connection to a dbI'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 *** Sent via Developersdex http://www.developersdex.com *** What happens if you remove "Initial Catalog=LibDB" from the connection string?
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 *** Sent via Developersdex http://www.developersdex.com *** Are you sure there is a database in your SQLServer with that name?
Robin S. ----------------------- Show quoteHide quote "Claudia Fong" <cdolphi***@yahoo.co.uk> wrote in message news:ud8qcVsWHHA.5008@TK2MSFTNGP05.phx.gbl... > 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 > > *** Sent via Developersdex http://www.developersdex.com ***
Show quote
Hide quote
"Claudia Fong" <cdolphi***@yahoo.co.uk> wrote in message If it's the first time you are trying to connect, how comes that you have a user DB called news:u0M4s$oWHHA.1396@TK2MSFTNGP05.phx.gbl... > 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 > > *** Sent via Developersdex http://www.developersdex.com *** LibDB? How did you create that DB without connecting to SQL? Willy. I created the db inside the VS 2005..
Cheers! Claudi *** Sent via Developersdex http://www.developersdex.com *** Claudia Fong wrote:
> I created the db inside the VS 2005.. Then you get a connection to the database in the server explorer window, > > Cheers! > > Claudi > > *** Sent via Developersdex http://www.developersdex.com *** right? Right click on that connection and choose Properties, there you can see what connection string VS uses. "Claudia Fong" <cdolphi***@yahoo.co.uk> wrote in message Ok, that means you did add a "Dataconnection" from within VS, so it should be possible to news:%23BzIHl0WHHA.4964@TK2MSFTNGP06.phx.gbl... >I created the db inside the VS 2005.. > > Cheers! > > Claudi > > *** Sent via Developersdex http://www.developersdex.com *** 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 On Feb 27, 9:54 pm, Claudia Fong <cdolphi***@yahoo.co.uk> wrote: Show quoteHide quote > 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 > > *** Sent via Developersdexhttp://www.developersdex.com***
Other interesting topics
dynamic length arrays
Marshaling variable length arrays Interlocked on a string? Serializing objects into application settings Overriding the add method of a generic dictionary How do a loop this program? Learning CSharp Xml Read Single Line at a time using C# "Logon failure" using Invoke("SetPassword"... How to add date in access database Showing HTML page in a windows application |
|||||||||||||||||||||||