Hi there I try to learn some ADO.NET. I'm working in Visual Studio 2015 using C#. I made a Database with some table in it which are stored on my local machine. Here is my C# code trying to connect to the database:
string constring = "Data Source=.; Database = CarShop;Integrated Security=SSPI";
SqlConnection con = new SqlConnection(constring);
con.Open();
An error is thrown when I try to Open the SqlConnection saying this:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll Additional information: 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.(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
So far I have tryied to change the connection string to something like:
string constring = "Data Source=192.168.0.101; Database = CarShop;Integrated Security=True;Connect Timeout=30";
or
constring = "Data Source=(LocalDB)/MSSQLLocalDB;AttachDbFilename=D:/Proiecte/Visual Studio/C#/DataBases/DataBaseTut2/DataBaseTut2/CarShop.mdf;Integrated Security=True;Connect Timeout=30";
But neither have worked.