Results 1 to 5 of 5

Thread: Unabel to connect to PUBS database

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    108

    Angry Unabel to connect to PUBS database

    Whenever I try to connect to the PUBS.MDF database, a login failed error message will appear.

    I defined the connection string in the web.config file like this:

    Code:
    <connectionStrings>
        <add name="Pubs" connectionString="Data Source = localhost\SQLEXPRESS; Initial Catalog=Pubs;Integrated Security=SSPI"/>
      </connectionStrings>
    And setup the connection in the click event of a button
    Code:
    Dim connectionString As String = WebConfigurationManager.ConnectionStrings("Pubs").ConnectionString
            
    Dim myConnection As New SqlConnection(connectionString)
    
    myConnection.Open()
    
    ..........
    And I put the PUBS.MDF file in the same folder as the vb source files.

    How do I connect to the database correctly?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Unabel to connect to PUBS database

    Don't place your MDF in the App_Code folder. It should be in the App_Data folder. Then, to "attach" it, use a connection string like:

    Code:
    Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    108

    Re: Unabel to connect to PUBS database

    I have tried the above connection string and have placed the database file in the app_data folder but there is still an error.

    The message is:

    Error reading the databaseDirectory lookup for the file "C:\ADONet\App_Data\PUBS.MDF" failed with the operating system error 5(Access is denied.). Could not attach file 'C:\ADONet\App_Data\PUBS.MDF' as database 'PUBS'.

    The connection string I used is:

    Code:
    <add name="Pubs" connectionString="Data Source = .\SQLEXPRESS;
    AttachDBFileName = C:\ADONet\App_Data\PUBS.MDF;Database=PUBS;
    Database=PUBS;Integrated Security=SSPI;Trusted_Connection=Yes"/>

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    108

    Re: Unabel to connect to PUBS database

    ok, i've found that when the AttachDBFileName is set to C:\PUBS.MDF, the connection string can work.

    But when I use the App_Data folder path, the connection does not work.

    What's wrong?

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Unabel to connect to PUBS database

    Go to the App_Data folder and check to see if ASPNET or NETWORK SERVICE users have full permissions on it.

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