Results 1 to 3 of 3

Thread: Connection String Issue

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    179

    Connection String Issue

    I am getting this error:

    {"An attempt to attach an auto-named database for file D:\WORK\DocStore\DocStore\Database\DocStore.mdf\ failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."}

    I verified the file exists and is checked out for edit.

    This is in my app.config:

    Code:
    <connectionStrings>
        <add name="DocStoreEntities" connectionString="metadata=res://*/Database.DocStore.csdl|res://*/Database.DocStore.ssdl|res://*/Database.DocStore.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|;Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True&quot;"
          providerName="System.Data.EntityClient" />
        <add name="DocStore.My.MySettings.DocStoreConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|;Integrated Security=True;User Instance=True"
          providerName="System.Data.SqlClient" />
      </connectionStrings>
    I am populating the DataDirectory like this:

    My.Settings.DatabaseLocation = "D:\WORK\DocStore\DocStore\Database\DocStore.mdf"

    AppDomain.CurrentDomain.SetData("DataDirectory", My.Settings.DatabaseLocation)

    Is it due to the "/" at the end of my .mdf\ ?

    If it is, where is it coming from?

    Any help would be greatly appreciated!

    Thanks,
    Eroc

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Dec 2005
    Posts
    179

    Re: Connection String Issue

    I tried removing the | but I take it that is what declares its a variable.

    Anyone have any ideas?

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Connection String Issue

    That indicates that the database can't be attached because a database with that name is already attached. It's likely that the database wasn't detached properly last time you ran the app. Try deleting the entire bin folder, which might require you to close VS first. If it won't delete then the database is still attached, so you might need to restart SQL Server. I know I had similar issues some time ago but I can't recall whether it righted itself or I had to do something specific.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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