Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 553 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An attempt to attach an auto-named database for file ....database1.mdf failed

#1
I am getting the following error while debugging my visual studio 2010 website:

> An attempt to attach an auto-named database for file C:\Users\...\Desktop\Dpp2012New\App_Data\dppdatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
>
> Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
>
> Exception Details: System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file C:\Users\...\Desktop\Dpp2012New\App_Data\dppdatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Here is my connection string from my `web.config`:

<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/>
<add name="ConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dppdatabase.mdf;Integrated Security=SSPI"
providerName="System.Data.SqlClient"/>
</connectionStrings>

And I access it from my website as:

Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

The stacktrace shows the error line as:

Dim conn As New SqlConnection(connectionString)
Dim dr As SqlDataReader
conn.Open() 'This is the error line as per stacktrace

I have given the needed permissions to the above folder so it can not be the " or specified file cannot be opened" issue. If we look at all the posts related to the same error in this forum, clearly the profoundness of this error can be found out. However, none of the solutions solves my issue.
Some of the resources which I have tried are:

1.

[To see links please register here]

2.

[To see links please register here]

3.

[To see links please register here]


I eagerly await a solution.


Reply

#2
check your web-config file, there may be more than one connection string having same name
Reply

#3
One of the most annoying errors when developing web apps in .Net. I had this issue on a project I was doing a year ago.
This is what worked for me: I've logged in with sa account to SQL Management Studio and attached the database to the object explorer (Databases -> Right Click -> Attach).
Then I've opened Security->Logins->[myWindowsUsername] and edited User Mappings tab, giving *dbowner* rights to the attached database.

I'm sure you can do those things without Management Studio, with console commands, but I'm not that good with T-SQL and can't give you advice on that.
Reply

#4
I had a similar error, but using a connection configured in code, rather than a config file. The solution for me was simply to add the "Initial Catalog=MyDatabase" part. My code now looks like...

DbConnection connection = new SqlConnection(String.Format(@"Data Source=.\SQLEXPRESS; Integrated Security=SSPI; AttachDbFilename={0}; User Instance=True; Initial Catalog=IPDatabase;", Location));

Location is a full path to an mdb file, that does not have to exist yet.
Reply

#5
Error was fixed for me after I changed this

ConfigurationManager.ConnectionStrings[0].ConnectionString

to this

ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString
Reply

#6
I have changed the installation folder from program files to C directory while I am installing the app. then my problem is solved
Reply

#7
well I think reason is that in your database directory, contains a .mdf file which has the same name. So best thing is to give the full path you can just replace the AttachDbFilename. just simply get the fullpath of the database file and assign it into the AttachDbFilename which is in app.config file.
Reply

#8
Mine was an EF code-first project and it comes up when the file has been deleted. Running `Update-Database` from the Package Manager Console makes the DB and its fine.
Reply

#9
Try to create your connection string as below:

<add name="ECommerce" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=C:\USERS\dL\DESKTOP\DATABASE\MYSHOP.MDF;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient"/>


It's working for me.
Reply

#10
I had this problem also and it was a pain. I configured my connection string and managed to solve the problem. In the connection string I replaced the value **|DataDirectory|\dbfilename.mdf** for **AttachDbFilename** property, with the path to the file. |DataDirectory| can only be used if the database file is in the App_Data folder inside same project.

So changing the AttachDbFilename property to the direct path of the mdf file, fixed my issue.

**AttachDbFilename=C:\MyApp\App\DAL\db.mdf**

I hope this works for you.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through