H.Ghassami
H.Ghassami

Reputation: 1022

SQL error on the database that i don't have it in my project?"An attempt to attach an auto-named database for file fail"

System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file E:\Market\Vina\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

I don't have this data base in my project and in my sql server,So why my connection has this error.?

<add name="Vina" 
     connectionString="Data Source=.\sqlexpress;Initial Catalog=MySite;Integrated Security=True"
     providerName="System.Data.SqlClient" /> 

and my code is:

SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["MySite"].ConnectionString);   

How can I fix it?

Upvotes: 0

Views: 100

Answers (1)

Steve
Steve

Reputation: 216363

That seems to be the default connection string for ASP.NET.
You could remove that definition using

<connectionStrings>
    <!-- Remove the inherited conn strings  -->
    <clear />

    <!--   This is your conn string -->
    <add name="Vina" connectionString="Data Source=.\sqlexpress;Initial Catalog=MySite;
               Integrated Security=True"
               providerName="System.Data.SqlClient" /> 
</connectionStrings>

Some reference on the <clear/> element

MSDN says

Removes all references to inherited connection strings, allowing only the connection strings that are added by the current add element.

Upvotes: 1

Related Questions