I am trying to use 2 databses in an application. Error is
Cannot attach the file 'D:\Documents\_VSC\ASP.NET\HazInfoSM\App_Data\evaris_rosql.mdf' as database 'evaris_rosql.mdf'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot attach the file 'D:\Documents\_VSC\ASP.NET\HazInfoSM\App_Data\evaris_rosql.mdf' as database 'evaris_rosql.mdf'.
web config rows
C#
what am I doing wrong?


Jignesh KumarRank #91 · 22.9K reputationPosted Jan 13, 2025, 12:05 AM EST
Hello Marius,
Please check you attachedDbFilename path is correct and fully accessible,
AttachDbFilename="D:\Documents\_VSC\Evaris\App_Data\evaris_rosql.mdf";Initial Catalog=evaris_rosql.mdf
Rather than using " use with
AttachDbFilename="D:\Documents\_VSC\Evaris\App_Data\evaris_rosql.mdf"
Marius VasileRank #785 · 2.9K reputationPosted Jan 19, 2025, 10:18 AM EST
Thank you Jignesh, I still have the error
Cannot attach the file 'D:\Documents\_VSC\ASP.NET\HazInfoSM\App_Data\evaris_rosql.mdf' as database 'evaris_rosql.mdf'.
with web.config like
However, if I declare the connection string locally, for example with
protected void GetObiectiv() { string connStringEvaris = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\Documents\\_VSC\\ASP.NET\\Evaris\\App_Data\\evaris_rosql.mdf;Integrated Security=True"; using (SqlConnection conn = new SqlConnection(connStringEvaris)) { string sqlQuery = "SELECT DISTINCT OID,Obiectiv FROM tblObiectiv ORDER BY Obiectiv"; using (SqlCommand cmd = new SqlCommand(sqlQuery, conn)) { cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); conn.Open(); DataSet ds = new DataSet(); da.Fill(ds); LV1.DataSource = ds.Tables[0]; LV1.DataBind(); conn.Close(); } } }is working very well. What am I doing wrong in web.config?
Marius VasileRank #785 · 2.9K reputationPosted Jan 19, 2025, 10:30 AM EST
It is working now, the path was not correct a folder was missing. :)