views:

69

answers:

5

I have problems connecting to my database server. The database server is not local, I am connected via its IP address.

It works fine in my development machine. After publishing the website to my server, it can not connect to my database server.

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)

Why can't my publish server connect to the database server, whereas it works fine through the development machine?

+1  A: 

I'll attempt to go two for two on the psychic debugging for today...

I will assume that you are not using integrated security? If so it might explain things as the account on your local machine probably has permissions, but the SYSTEM account that is running on the server does not. Just a shot in the dark though.

Josh
Your picture makes you look like there's a good chance your psychic.
Abe Miessler
I changed added this to the connectionstrngIntegrated Security=SSPI;and it didn't work
nezdet
@nezdet: Your change actually added Windows authentication explicitly. The problem you're having, if it is what Josh suggests, will persist unless you change the credentials under which your web server is running to a set that has database access (your own, for example, although you should always try to use service accounts for web servers.
Mike Burton
@nezdet -- What I am suggesting is that you explicitely use an account in your connection string to use a known SQL Account that has access: username=BillyBob;password=ILikeCorn;
Josh
Iam using a SQL account that is known, it works fine from amanagment stuiod and development machine, but when publishing than it dosen't connect,
nezdet
A: 

It sounds like your server can't make the network connection, rather than a security issue.

  • Ensure that any firewalls on both the DB and app servers allow traffic on the port (1433).
  • Ensure you're able to ping or tracert from both machines.
p.campbell
pinging works from both servers, I closed down firewall on the publish server,
nezdet
+1  A: 

I often had that problem. Mostly it's because of two problems.

  1. Open the SQL Server Configuration Manager.

    • Check if the SQL Server Network Configuration supports TCP/IP, if it's disabled, enable it. e.g. SqlServer 2005 Network Configuration, Protocols for SQLEXPRESS
  2. Open the SQL Server Management Studio

    • Click on the Sql Server Properties (right click on the server name and select properties).
    • After that, select the page "Security" and switch the check to "SQL Server and Windows Authentication mode".

That's all.

BitKFu
This was already done: - TCP/IP is enabled- and SQL Server and "Windows Authentication mode" is also checked,
nezdet
Connecting from my Client works fine, but now from the server. I don't know why
nezdet
Maybe on the server, the client protocol does not allow TCP/IP. You can check that on your server with the SQL Server Configuration Manager too. So you only have to look for "SQL Native Client Configuration/Client Protocols"
BitKFu
it is enabled, I can't understand why it works on the development machine, but not on the publish server
nezdet
A: 

Is it your first time you publish your website on the web server ? if it is , Are you sure you have set your connection string properly ?

You need to create a login ( of curse a password for that too ) and the IP Address of that SQL on the web server .

So you need IP Address of the sql server host , Database Name , UId , Pwd .

Mostafa
It not first time, I have some other applications that are connected localy to the database, this app connects to a server that is not in local,
nezdet
A: 

I will agree that this sounds like a network issue and not a security issue.

Remote into the web server and ping the DB server by IP address. If this does not work, your server cannot see the DB server via that address (different subnet, incorrect firewall/proxy setup, etc). There may be a proxy address you must use to get to the DB server from the web server, or your web server may also be the gateway and IIS doesn't know to look for the DB server on the LAN. If it does work, the computers may not be talking on the same port, or the firewall may be blocking that port exiting the web server.

KeithS