1

I have a SQL connection setup like this in web.config:

<connectionStrings>
    <add name="MyConnectionString" connectionString="Data Source=SQLServer;Initial Catalog=DBName;User ID=domain\username;Password=password
      providerName="System.Data.SqlClient" />
  </connectionStrings>

On my dev machine all works fine, but when putting on web server I keep getting:

Inner Exception Type: System.ComponentModel.Win32Exception
Inner Exception: The network path was not found
Inner Source: 
Exception Type: System.Data.SqlClient.SqlException
Exception: 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)

The web server has no problem reaching the SQL server, I am guessing there is something wrong with my connection string syntax.

Can anyone spot anything wrong?

sd_dracula
  • 3,796
  • 28
  • 87
  • 158
  • 4
    Data Source should be the name of the PC where SQLServer is installed – Steve Jun 04 '14 at 11:24
  • 1
    How do you verify that `The web server has no problem reaching the SQL server`? – qxg Jun 04 '14 at 11:24
  • Also look carefully [at this question](http://stackoverflow.com/questions/1229691/difference-between-integrated-security-true-and-integrated-security-sspi) for the Integrated Security part – Steve Jun 04 '14 at 11:25
  • Well from the web server I can connect to the SQL server using SSMS and I have actually removed the Integrated Security part, just forgot to remove it from the main body. – sd_dracula Jun 04 '14 at 11:33
  • Just copy the server value present in the SSMS Login screen to your connection string – Steve Jun 04 '14 at 11:35
  • I would highly recommend bookmarking this site: https://www.connectionstrings.com/ – freefaller Jun 04 '14 at 11:37
  • The network path wasn't found, so what exactly is the network path to your SQL server? :) – Maritim Jun 06 '14 at 13:20

3 Answers3

1

if you are using the SQL Express then use like

<connectionStrings>
<add name="MyConnectionString" connectionString="Data Source=Server\SqlExpress;Initial Catalog=DBName;User ID=username;Password=password
  providerName="System.Data.SqlClient" />

update if it working fine

Max
  • 12,622
  • 16
  • 73
  • 101
suresh
  • 11
  • 2
0

Is it your SQL Express edition ? if yes then go with following connection string

DATA SOURCE=ipaddress_of_sql_machine\sqlexpress;UID=sa;PWD=;DATABASE=databasename

if you don't have sql express then go for following connection string

DATA SOURCE=ipaddress_of_sql_machine;UID=sa;PWD=;DATABASE=databasename

hope it helps

koolprasad2003
  • 299
  • 3
  • 23
0

Check if your machine and server are in different domain. This may help :

http://www.codeproject.com/Questions/335874/A-network-related-or-instance-specific-error-occur

Mukesh Modhvadiya
  • 2,178
  • 2
  • 27
  • 32
  • The web server and the SQL server are in different domains, but both are sub-domains of the same domain. – sd_dracula Jun 04 '14 at 11:42
  • I was asking about your development machine where your code worked and your server, if they are on different domain. – Mukesh Modhvadiya Jun 04 '14 at 11:46
  • they are but I think I've found the issue, the web server is dual homed and while it can reach the SQL server it seems to not want to connect anyway. I've tried connecting with SSMS on the web server to SQL server and the same error happens – sd_dracula Jun 04 '14 at 12:05