Question

I'm currently doing my final year university project using C# via Visual Studio 2012 and SQL Server 2012 Management Studio. I'm having trouble trying work on my project at home due to connection to my SQL Server on my machine. In class we have set the connection string using Resources :

Name: conStr

Value: Data Source = localhost;Initial Catalog = computer warehouse;Integrated Security = true

And using

cnStr = Properties.Resources.conStr;
sqlCustomers = @"Select * from Customers";

daCustomer = new SqlDataAdapter(sqlCustomers, cnStr);
cmdCustomers = new SqlCommandBuilder(daCustomer);

daCustomer.FillSchema(dsCustomer, SchemaType.Source, "Customers");
daCustomer.Fill(dsCustomer, "Customers");

In the form load

I have both SQL Server and Visual Studio on my Home Machine and have created the connection through Visual Studio, Created the Database on SQL and accuired the new Connection String

Data Source=NIALL\SQLEXPRESS;Initial Catalog=computer warehouse;Integrated Security=True

However when I run the program i'm getting this error

A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information is telling me The server was not found or was not accessible

Any help is appreciated

No correct solution

OTHER TIPS

Verify that the connection string is correct, because you're receiving an exception saying that the server isn't accessible.

Loading it from the resources shouldn't matter. Place it in your code directly, and then make sure everything is working fine.

An easy way to help you figure out the correct connection string is to create a file with the UDL extension (ie connection.udl). Opening this will let you use a dialog to test your connection and then will give you the exact connection string to use. See here: https://social.technet.microsoft.com/wiki/contents/articles/1409.how-to-create-a-sql-connection-string-for-an-application-udl-file.aspx

I think the problem is with your Data Source setting in the connection string. If you only have one instance of SQL Server running on your home machine localhost should work, but if you need to refer to the server via the server instance name, make sure you have the SQL Server Browser service started for your instance. I think this is needed if you are referring to the data source using an instance name like NIALL\SQLEXPRESS.

I allowed the database to except remote connections, and following all the other advice - all it took then was a restart.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top