Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys, me again

OK so ive now detached the database from SQL Server manager, and as predicted it no longer connects, now ive added the detached files the .mdf and the log file from the detached database, and it has given me the application services connection string , as shown below, this is the actual connection string in the Web.config:

<pre><connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
      providerName="System.Data.SqlClient" />
    <add name="TravelShopConnectionString1" connectionString="Data Source=MATTHEW-PC\SQLEXPRESS;Initial Catalog=TravelShop;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>


now i know the bottom one is the direct connection to my home computer through SQLEXPRESS, and the top one is the generated string from the copied file, but the error remains the same when trying to use it in the c# code like this:

C#
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString);


does it need to be a direct file path name to the copied database?

this is the error:

[SqlException (0x80131904): An attempt to attach an auto-named database for file 
C:\Users\Matthew\Desktop\testing conections\TheTravelShop\TheTravelShop\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.


what does this actually mean? apart from it already exists, although i did exclude the original from the application in the server explorer.


Thanks for reading
Matt.
Posted
Updated 16-Apr-12 8:59am
v5

1 solution

Stupid me....

<add name="ApplicationServices" connectionstring="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providername="System.Data.SqlClient" />



didnt change the direct name of the .mdf file from aspnetdb.mdf to TravelShop.mdf.

the most simplest of things......

Thanks for viewing
Regards
Matt.
 
Share this answer
 
Comments
Nelek 16-Apr-12 16:51pm    
Don't worry, that happens to all of us soon or later, specially after a hard day ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900