shilpa sonawane

shilpa sonawane

  • NA
  • 8
  • 14.2k

To write dynamic connection string(c#2008,SQL SERVER 2005)

Mar 7 2012 8:23 AM
I have used Attach a database file, located in the data directory, on connect to a local SQL Server Express instance.code is
conn = new SqlConnection();
conn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\carRent.mdf;Integrated Security=True;User Instance=True";
return conn;
But I get error :

Unable to open the physical file "D:\CarRent Completed\CarRent\bin\Debug\carRent.mdf". Operating system error 32: "32(The process cannot access the file because it is being used by another process.)".
An attempt to attach an auto-named database for file D:\CarRent Completed\CarRent\bin\Debug\carRent.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
how to solve this error?Thanks for your time and consideration.

Answers (1)