473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

trouble with connection to a db

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 ***
Feb 27 '07 #1
8 1290
What happens if you remove "Initial Catalog=LibDB" from the connection string?

--
Cheers,
Stefan Delmarco

http://www.fotia.co.uk

Feb 27 '07 #2
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 ***
Feb 27 '07 #3
Are you sure there is a database in your SQLServer with that name?

Robin S.
-----------------------
"Claudia Fong" <cd********@yahoo.co.ukwrote in message
news:ud**************@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 ***

Feb 28 '07 #4
"Claudia Fong" <cd********@yahoo.co.ukwrote in message
news:u0**************@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 ***


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.

Feb 28 '07 #5
I created the db inside the VS 2005..

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Feb 28 '07 #6
Claudia Fong wrote:
I created the db inside the VS 2005..

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***
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.

--
Göran Andersson
_____
http://www.guffa.com
Feb 28 '07 #7
"Claudia Fong" <cd********@yahoo.co.ukwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>I created the db inside the VS 2005..

Cheers!

Claudi

*** Sent via Developersdex http://www.developersdex.com ***

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.

Feb 28 '07 #8

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.ukwrote:
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***

Mar 1 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alistair | last post by:
Hi there, New to PHP. I have always used ASP. I am having trouble trying to do the things in PHP the way (or similar) i did it in ASP. In ASP I used an Access database. I now use a mySQL...
1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
14
by: BlackHawke | last post by:
My Name is Nick Soutter, I am the owner of a small game company, Aepox Games (We're in the middle of a name change from "Lamar Games"), www.lamargames.net. Our first commercial game,...
14
by: jj | last post by:
Is it possible to call a remote php script from within Access? I'm thinking something like: DoCMD... http://www.domain.com/scripts/dataquery.php DoCmd.OpenQuery "update_data", acNormal, acEdit...
4
by: Brent Waldrop | last post by:
Ok everyone, i have been pulling my hair out on this one. I have been working on it for 3 days with no sucess. This problem is occuring at home where i am running a workgroup. I have Windows 2003...
2
by: somersbar | last post by:
im trying to get a table from a microsoft access database on a simple web form using visual basic.net. ive set up the database as a file dsn. this is my connection string: DBQ=C:\Program...
5
by: mlg1906 | last post by:
I'm developing an intranet site in ASP.NET 2.0 but I can't seem to connect to the DB from within my code. I've created a .vb class that houses a private Connection() that other functions within the...
0
by: joshblair | last post by:
Hello, I am trying to post XML documents to a third party using the HttpWebRequest. This URL uses HTTPS (SSL) but I don't have a client certificate to deal with. Apparently they are using...
0
by: mrchatgroup | last post by:
news from http://www.mrchat.net/myblog/myblog/small-accidents-mean-big-trouble-for-supercollider.html Small Accidents Mean Big Trouble for Supercollider Image Scientists expect startup...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.