IIS:连接到 .mdf 数据库 - Web 配置问题

发布于 2024-10-08 22:32:22 字数 955 浏览 6 评论 0 原文

我在本地连接到 Northwind.mdf,但是当我将应用程序上传到远程服务器时,出现以下错误:

与网络相关或特定于实例的 建立时发生错误 连接到 SQL Server。服务器 未找到或无法访问。 验证实例名称是否为 正确并且 SQL Server 是 配置为允许远程 连接。 (提供商:SQL 网络 接口,错误:26 - 错误定位 指定服务器/实例)

这些是我尝试过的几个选项:

<connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>

上面的一个在本地工作。

<connectionStrings>
            <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ASP\TestSite\App_Data\Northwind.mdf; Integrated Security=True;Connect Timeout=30;User Instance=True;Trusted_Connection=Yes"/>
        </connectionStrings>

服务器上安装了 SQL Server 2005

谢谢,
伊利亚

Locally I connect to Northwind.mdf but when I upload application to remote server then I get following 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: SQL Network
Interfaces, error: 26 - Error Locating
Server/Instance Specified)

These are few options I tried:

<connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Northwind.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>

The above one work locally.

<connectionStrings>
            <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ASP\TestSite\App_Data\Northwind.mdf; Integrated Security=True;Connect Timeout=30;User Instance=True;Trusted_Connection=Yes"/>
        </connectionStrings>

On server is installed SQL Server 2005

Thanks,
Ilija

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

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

发布评论

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

评论(4

耳根太软 2024-10-15 22:32:22

请按照下列步骤操作:
1:使用 Sql Server Management studio 将 Northwind.mdf 连接到服务器上的 Sql Server 2005。
2:修改 web.config 中的连接字符串,使其指向服务器上的数据库。

如何分离/附加数据库。

Follow these steps:
1: Attach your Northwind.mdf to your Sql Server 2005 on your server using the Sql server Management studio.
2: Modify the connectionstring in your web.config so that it points to the db on your server.

How to detach / attach db.

倒带 2024-10-15 22:32:22

有几点需要检查:

  1. 数据库文件是否真的位于该位置?
  2. 应用程序池是否具有该目录的读/写权限?
  3. SQL Express 服务是否实际运行?

A couple things to check:

  1. Is the database file really at that location?
  2. Does the app pool have read/write rights to that directory?
  3. Are the SQL Express services actually running?
夏日浅笑〃 2024-10-15 22:32:22
Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\ASP\TestSite\\App_Data\\Northwind.mdf;Integrated Security=True;User Instance=True

然后阅读如何配置 SQL Server 2005 以允许远程连接

并确定 Northwind 的位置。 mdf是对的!

Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\ASP\TestSite\\App_Data\\Northwind.mdf;Integrated Security=True;User Instance=True

And then read How to configure SQL Server 2005 to allow remote connections

And be sure the location of Northwind.mdf is right!

不乱于心 2024-10-15 22:32:22

以下是需要检查的几点:

  • 如果您要部署到共享托管环境中,则主机很可能不会在 Web 服务器上运行 SQL Server。请他们确认并向您提供 。

  • 您使用的连接字符串看起来很可疑。如果您的服务器上已安装 SQL Server,但作为“默认”实例,则您不需要连接字符串 数据源\SQLEXPRESS 部分。只需使用 .(local).

  • 如果确实安装了 SQL Express,并且是使用实例名称 SQLEXPRESS 安装的,则检查站点身份是否具有有效的登录名以及对数据库的正确权限。此身份可以是工作进程帐户(NETWORK SERVICEApplicationPoolIdentity、自定义帐户)或网站的 IIS 匿名帐户(如果启用了 ASP.NET 模拟)。

我的最后一点很重要:

  • AttachDbFilenameUser Instance=True 特定于 SQL Express,它支持称为“用户实例”。此功能适合专用或共享托管环境。

我的建议是

  • 准确找出可供您使用的 SQL Server 版本和版本
  • 找出其托管位置(在您的服务器本地或另一台计算机上)
  • 找出它是否配置为“默认”实例或命名实例

Here's couple of points to check:

  • If you're deploying into a shared hosting environment the chances are that the host won't be running SQL Server on the web servers. Ask them to confirm and provide you with the .

  • The connection string you're using looks suspicious. If SQL server has been installed on your server but as the "Default" instance then you don't need the \SQLEXPRESS part of the connection string Data Source. Just use . or (local).

  • If it is indeed SQL Express installed and it's been installed with the instance name SQLEXPRESS then check that the site identity has a valid login and the correct permissions on your database. This identity could be the worker process account (NETWORK SERVICE, ApplicationPoolIdentity, custom account) or the site's IIS anonymous account (if ASP.NET impersonation is enabled).

My final point is important:

  • The AttachDbFilename and User Instance=True are specific to SQL Express which supports a concept known as "User Instances". This feature is not suitable for dedicated or shared hosting environments.

My advice is to

  • find out exactly what version AND edition of SQL Server is available for you to use
  • find out where its hosted (locally on your server, or on another machine)
  • find out if it's configured as the "Default" instance or a named instance
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文