views:

18

answers:

1

Hi,

I create a database in SQL Server 2008 Express (Advanced). Then i have a connection string in my C# using 'SharpDevelop' IDE, Version : 3.2.0.5777, .NET Version : 2.0.50727.3615

<add name="ConnectionString" connectionString='Data Source=.\SQLEXPRESS;AttachDbFilename="D:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\SpringTesting.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True' providerName="System.Data.SqlClient" />

When application tries to connect to this database (SpringTesting), i get this exception

An attempt to attach an auto-named database for file E:\STS_Client\SpringEfficiency\TestProject1\bin\Release\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

I am not doing anything related to ASP.NET. Any ideas on how to prevent this ?

Thanks, Chak.

+2  A: 

The connection string that you are using is telling SQL to attach the database. Since you have already created the database it is complaining.

Change the connection string to connect to the database you have created:

Server=.\SQLEXPRESS; Initial Catalog=SpringTesting;Integrated Security=True;
Mark PM
Thanks but i did that and get the same error. There are responses to this problem on the web but they have too many things that we need to try out !
Chakra
Chakra
http://blogs.msdn.com/b/astebner/archive/2005/09/13/465401.aspx this also helped
Chakra