简体   繁体   中英

Error connecting to SQL Server via alias from local IIS7

Just wondering if anyone has run into this before. Had a few devs look at this, and none of us can figure it out.

I have an ASP.NET Web Forms app connecting to a Sql Server db via an alias using EF4. The alias is set to point to my machine name (not "." or "local"). When I run it out of VS2012, it works fine. If I deploy it to my local instance of IIS7 and try to pull it up in a browser, I get the 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)

My connection string looks like this:

Data Source=aliasName;Initial Catalog=databaseName;Integrated Security=True;MultipleActiveResultSets=True

If I change the connection string so that the Data Source is my machine name instead of the alias, it works fine from IIS7. So, the problem appears to be something with the alias and only when running out of IIS7.

As a workaround, I am using a local build profile to deploy a different web.config that doesn't use the alias locally, but I would really like to figure out why it's not working.

Any advice would be appreciated.

Check this , specifically:

Pre-requisites for SQL Server Alias usage

  1. You must be willing for your clients to connect to the instance via a network protocol. It is not possible to use shared memory connections that are available when the client and instance are on the same system. I use TCP/IP connections for my aliases.

  2. On the system hosting the SQL Server instance you must have the SQL Server Browser service running (this is normally has Start Mode set to Automatic).

  3. On a 64-bit system, if you have both 32-bit and 64-bit clients, you will need to create an alias for BOTH 32-bit and 64-bit clients.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM