Home All Groups Group Topic Archive Search About

trouble with connection to a db

Author
27 Feb 2007 4:54 PM
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

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

Author
27 Feb 2007 5:11 PM
Stefan Delmarco
What happens if you remove "Initial Catalog=LibDB" from the connection string?

--
Cheers,
Stefan Delmarco

http://www.fotia.co.uk
Are all your drivers up to date? click for free checkup

Author
27 Feb 2007 11:16 PM
Claudia Fong
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 ***
Author
27 Feb 2007 11:50 PM
RobinS
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 ***
Author
28 Feb 2007 8:25 AM
Willy Denoyette [MVP]
Show quote Hide quote
"Claudia Fong" <cdolphi***@yahoo.co.uk> wrote in message
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 ***



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.
Author
28 Feb 2007 3:01 PM
Claudia Fong
I created the db inside the VS 2005..

Cheers!

    Claudi

*** Sent via Developersdex http://www.developersdex.com ***
Author
28 Feb 2007 3:16 PM
Göran_Andersson
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
Author
28 Feb 2007 3:31 PM
Willy Denoyette [MVP]
"Claudia Fong" <cdolphi***@yahoo.co.uk> wrote in message
news:%23BzIHl0WHHA.4964@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.
Author
1 Mar 2007 5:33 AM
Geek
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***

Bookmark and Share