iv'e got copy of NORTHWND.mdf along with NORTHWND.LOG in my App_Data folder
MY CONNECTION STRING :
<add name="northwind_connection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|NORTHWND.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
when i attempt to open and close the connection everything works out fine.
string connStr = WebConfigurationManager.ConnectionStrings["northwind_connection"].ToString();
SqlConnection conn = new SqlConnection(connStr);
SqlCommand command = new SqlCommand("Select * From Products");
command.Connection = conn;
conn.Open();
SqlDataReader reader = command.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
conn.Close();
now beside this code i want to add SqlCacheDependency to the page when i place the code : Shown in msdn
SqlDependency.Start(connStr);
I GET THE FOLLOWING ERROR :
An attempt to attach an auto-named database for file C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\NORTHWND.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
any ideas why this happens , what do i need to configure for the SqlCacheDependency to work.
thanks in advance eran.
in addition i would like to add that if i change my connection string to a specific one
<add name="northwind_connection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\NORTHWND.MDF; Integrated Security=True" providerName="System.Data.SqlClient" />
everything works as it should but that seems wrong since i don't expect users to change the connection string to their path , that's why i would like to put it in App_Data or at list give a relative path to .\SQLEXPRESS which also doesn't work :
<add name="myConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=NORTHWND;Integrated Security=True;" providerName="System.Data.SqlClient"/>
please shed some light on this issue there must be some configuration that makes this possible . thanks in advance. eran.