New to using SQL Server inside of Visual Studio.
I am trying to create a portable program that will read in a CSV file and insert the data into a database.
I have created the database and added the .mdf
file to my solution. However I cannot for the life of me figure out how to create a SqlConnection
to said database.
The error I get is:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
The database is named testdb.mdf
and here is a snippet of the code I have tried:
openCon = new SqlConnection();
openCon.ConnectionString = "Data Source=(LocalDB)\v11.0;" +
"AttachDbFilename=" +
AppDomain.CurrentDomain.BaseDirectory +
"testdb.mdf;" +
"Integrated Security=True";
openCon.Open();
I still receive the error after having tried the "duplicate post solution":
openCon.ConnectionString = "Data Source=.\\SQLEXPRESS;" +
"AttachDbFilename=" + AppDomain.CurrentDomain.BaseDirectory + "Encounter.mdf;" +
"Integrated Security=True";