2

Hi I'm writing a simple console application to save XML data into the database using bulkcopy but am currently having problems connecting to my database.

I am getting a SqlException error:

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)

I have checked for issues ensuring my SQL server is running and that it's configured correctly. Below is my connection string.

string connectionString = @"Data Source=SYAZANA;Initial Catalog=WangSCM;integrated security=true;" ;

I'm at my wits ends trying to figure out the error, what is the mistake that I'm making?

zana
  • 259
  • 2
  • 4
  • 15
  • Is the SQL Server on the same machine as the program or not? If not, check your firewall on the SQL Server side. Port 1433 (default instance) should be open at least. https://support.microsoft.com/de-ch/kb/968872/en-us for more ports used by SQL Server – Scoregraphic May 22 '15 at 09:31
  • @Scoregraphic thank you for the reply, yes they're on the same machine and i've checked that it's port 1433 – zana May 22 '15 at 09:50
  • @zana Please upvote and accept the answer if it worked for you – Reyan Chougle Oct 04 '17 at 18:29

2 Answers2

2

Follow the steps:

*Go to SQL Server Configuration manager

*SQL Server Network Configuration:

*Protocol for MSSQLSERVER

*In the right pane split page you will have to disable VIA as follows

--->Shared Memory - Enable

--->Named Pipes - Enable

--->TCP/IP - Enable

--->VIA - Disable

Or Try the following

Go to Start -> in search type Services.msc. There you will find services which are available in your system.

There look for -> SQL EXPRESS / SQL Server (SQLEXPRESS) -> Right click on it -> then Start it . If it is already in Start. Just Stop and start or simply Restart it.

Balaji
  • 1,375
  • 1
  • 16
  • 30
0

I had the same problem and for some reason I had to add the standard SQL port (1433) and then everything worked again. In your case that would be:

string connectionString = @"Data Source=SYAZANA,1433;Initial Catalog=WangSCM;integrated security=true;"
Ogglas
  • 62,132
  • 37
  • 328
  • 418