将 SQL Server 连接到 MVC3 应用程序时出错 - 与网络相关或特定于实例的错误

发布于 2024-11-29 02:35:41 字数 881 浏览 0 评论 0原文

由于我已将 mvc3/实体框架站点从本地主机移至实时服务器,因此出现此错误。通常,当我收到此错误时,我会检查连接字符串中的数据库名称、密码和服务器是否正确。我已经检查过了 - 它们看起来都很好。

我在数据库中的网站上有 aspnet 会员资格提供程序,它允许我登录,验证我,然后尝试将我重定向到另一个页面,然后这就是错误发生的地方 - 即,一旦我连接到数据库会员提供商。

数据库与站点位于同一服务器上,当我从本地主机连接到远程服务器时,它工作正常。

这是完整的错误消息:

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 connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

这是连接字符串:

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

有什么我可以尝试的吗?

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 connections. (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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤独岁月 2024-12-06 02:35:42

好吧,尽管我的网络配置中有连接字符串,但它实际上被忽略了,并且应用程序仍在尝试连接到本地版本。显然,您需要通过 dbContext 构造函数传递连接字符串,如下所示。

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

问题已在这里得到解答

无论如何,感谢您的帮助。

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.

不知所踪 2024-12-06 02:35:42

尝试删除数据源和初始目录,并将它们替换为以下内容:

Server=.\SQLEXPRESS;Database=BlueLadder;

我不知道您是否使用 SQLEXPRESS,所以如果您没有使用,请进行相应修改。

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.

驱逐舰岛风号 2024-12-06 02:35:42
  1. 检查您的服务器是否接受远程连接并启用 TCP/IP 提供程序。您可以使用服务器上的“Sql Server 配置管理器”进行配置

  2. 您可以尝试指定服务器的命名实例。 “Sql Server 配置管理器”可以告诉您服务器上安装了哪些实例。

服务器 = 192.168.1.43/MSSQLSERVER 或
服务器 = 192.168.1.43/SQLEXPRESS

  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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文