开发者

Error connecting SQL server to MVC3 application - A network-related or instance-specific error

I'm getting this error since I've moved my mvc3/entity framework site onto the live server from localhost. Normally when I would get this error, I'd check the database name, password and server are all correct in the connection string. I have checked this - they all seem fine.

I have aspnet Membership provider on the site within the database, and it allows me to login, verifies me, then tries to redirect me to another page, and then that's where the error happens - i.e., as soon as I connect to the database outwith the membership provider.

The database is on the same server as the site, and when I connect from localhost to the remote server, it works perfectly.

Here is the full error message:

Exception message: 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 connection开发者_Python百科s. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Here is the connection string:

<add name="ApplicationServices" connectionString="Data Source=192.168.1.43;Initial Catalog=BlueLadder;User Id=BlueLadderAdmin;Password=Auth1991;timeout=30" />

Anyone anything I could try?


Ok, despite my connection string in the web config, it was actually being ignored and the application was still trying to connect to a local version. Apparently you need to pass the connection string through the dbContext constructor, like so.

public Context()
            : base("ConnectionString")
        {
        }

Question was answered here

Thanks for your help anyway.


Try removing the Data Source and Initial Catalog, and replace them with something like this:

Server=.\SQLEXPRESS;Database=BlueLadder;

I don't know if you're using SQLEXPRESS, so just modify accordingly if you're not.


  1. Check if your server is accepting remote connections and has TCP/IP provider enabled. You can configure this using "Sql Server Configuration Manager" on your server

  2. You could try specifying the named instance of your server. "Sql Server Configuration Manager" can tell you what instances are installed on your server.

Server = 192.168.1.43/MSSQLSERVER or Server = 192.168.1.43/SQLEXPRESS

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜