Results 1 to 10 of 10

Thread: "Cannot open database. Login Failed."

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    164

    "Cannot open database. Login Failed."

    My first time trying to log in to my local sqlserver with VS2010 was greeted by this vague, unhelpful error:

    "Cannot open database "Database1.sdf" requested by the login. The login failed.
    Login failed for user 'KIDS-2CC578145'."

    I use SQL Express 2008. Here's my code for setting the connection string:

    Code:
    Dim connstring As String = "Data Source=(local)\SQLEXPRESS;Database=Database1.sdf;Integrated Security=True"
            Dim sqlcon As New System.Data.SqlClient.SqlConnection
            sqlcon.ConnectionString = connstring
            sqlcon.Open()

    i'm guessing there's something wrong with the ConnectionString but it's really not that intuitive to me help is appreciated.
    Last edited by acrym; Oct 2nd, 2011 at 12:21 AM.

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: "Cannot open database. Login Failed."

    You are trying to connect to database using windows authentication (Integrated Security=True), which will check for the current user name in the sql database and the the db missing that user. Check in users section for the current user,create new one if required
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    164

    Re: "Cannot open database. Login Failed."

    Sorry but, where can i do that. I can't find any sign of a users section in my project or online resources.

  4. #4
    Lively Member
    Join Date
    Sep 2011
    Posts
    99

    Re: "Cannot open database. Login Failed."

    First thing how did you setup your sql server? did you provide like a "mix password" or just clicking next next next. if you remember you provide a password for that.

    use this as connection string
    Code:
    Data Source=myServerAddress\SQL Instance Name;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
    or try this if you don't recall it
    Code:
    Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
    it should work.

    and hope it help you.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    164

    Re: "Cannot open database. Login Failed."

    I didn't ever provide a username or password, I just went to "New Item" ---> "Local Database" "Next (on Dataset)" ---> "Finish". I tried the Trusted Connection and I got the same error.

    This time I tried providing the full path of Database1.sdf but it still didn't work.

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: "Cannot open database. Login Failed."

    Try this connection string...

    Data Source=MyData.sdf;Persist Security Info=False;
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2010
    Posts
    164

    Re: "Cannot open database. Login Failed."

    Still no luck.....

  8. #8
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: "Cannot open database. Login Failed."

    sigh... you're mixing your sql server types... sdf file is a SQL Compact Edition file... not a normal SQL Server file... therefore you can't use the SQLClient namespace... and the connection string is all wrong...

    for a SQL CE it's this:
    Data Source=MyData.sdf;Persist Security Info=False;
    nothing more, nothing less.... you specify the name of the sdf if it is in the current directory, or you can specify the full path. Alternatively you can specify Data Source=|data|\myData.sdf if the file is going to be in the app data path (recommended).

    If you are connecting to SQL Server (full or express) then you use this format:
    Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

    Note that myServerAddress is either a named server, (local) for the local machine or an IP address.
    The myDataBase is the NAME of the database... Northwind, Pubs, Master, etc... NOT the name of a file.

    ConnectionStrings.com

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Lively Member
    Join Date
    Sep 2011
    Posts
    99

    Re: "Cannot open database. Login Failed."

    i was thinkin about that techgnme, the normal databse of sql is .mdb w/c what he is referring is .sdf.
    now i know too, i was confused on that lately

  10. #10
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: "Cannot open database. Login Failed."

    mdb = Access database
    mdf = SQL Server database file (main data file)
    ldf = SQL Server database log file
    ndf = SQL Server database file (when multiple files are used)
    sdf = SQL Server Compact Edition database file

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width