sql server 2005 Express 共享主机上的连接字符串问题

发布于 2024-08-31 07:44:00 字数 990 浏览 2 评论 0原文

我在连接到共享主机上的数据库时遇到问题。我的主机提供商说他们在他们的数据库上部署了 SQL 2005 Express,我按如下方式准备了连接字符串以利用 SQL Express。

<add name="PMIS_DBConnectionString" connectionString="Server=localhost;AttachDBFilename=|DataDirectory|PMIS_DB.mdf;Database=PMIS_DB;Trusted_Connection=Yes" />
  </connectionStrings>
  <system.web>\

我最初使用的数据源名称是./SQLExpress,但是我的主机提供商要求我将其更改为本地主机,虽然前者没有连接,但仍然按照上面所示的更改,访问时仍然出现错误到我的默认页面。错误如下: “/”应用程序中的服务器错误。 键“attachdbfilename”的值无效。

描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.ArgumentException:键“attachdbfilename”的值无效。

源错误:

第 120 行:公共函数 GetID(ByVal sLgaName As String) As Integer 第 121 行:Dim q As String = "Select PLID " & “来自 LGA”& "其中 LGAName = " & “'”& sLgaName & “'” 第 122 行:Dim cn As New SqlConnection(Me.ConnectionString) 第 123 行:Dim cmd As New SqlCommand(q, cn) 第 124 行:

我在网上读了很多书,并在谷歌上搜索到了这一点,我的手指已经麻木了。我有一个交付这个项目的最后期限,并且已经成功构建了应用程序,但发生这种情况令人沮丧。请帮我。

I have a problem connecting to my db on a shared hosting. My host provider says they deployed SQL 2005 express on their database and I prepared my connection string as follows to take advantage of sql express.

<add name="PMIS_DBConnectionString" connectionString="Server=localhost;AttachDBFilename=|DataDirectory|PMIS_DB.mdf;Database=PMIS_DB;Trusted_Connection=Yes" />
  </connectionStrings>
  <system.web>\

The data source name I used originally was ./SQLExpress, but my host provider asked that I change it to local host, although with the former it didn't connect, but still with the change as indicated above the error still comes up on access to my default page. The error is as follows:
Server Error in '/' Application.
Invalid value for key 'attachdbfilename'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Invalid value for key 'attachdbfilename'.

Source Error:

Line 120: Public Function GetID(ByVal sLgaName As String) As Integer
Line 121: Dim q As String = "Select PLID " & "From LGA " & "Where LGAName = " & "'" & sLgaName & "'"
Line 122: Dim cn As New SqlConnection(Me.ConnectionString)
Line 123: Dim cmd As New SqlCommand(q, cn)
Line 124:

I've read up a lot on the web and Googled my fingers numb on this. I have a deadline to deliver this project and having successfully built the app it's frustrating for this to happen. Please help me.

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

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

发布评论

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

评论(1

葬心 2024-09-07 07:44:00

您的托管提供商是否支持可附加数据库(即 AttachDBFileName?)。大多数托管提供商不允许这样做。错误消息似乎非常强烈地表明情况就是如此。可附加数据库是 Express 独有的功能,托管提供商在共享实例上为每个帐户提供一个数据库,我没有听说过提供商为每个帐户提供 Express 实例。

因此,您将连接到共享实例上由提供商为您创建的指定数据库,而不是连接到您复制的 MDF 文件。现在为了部署您的架构,您需要使用构建应用程序架构的各种 CREATE TABLE、CREATE VIEW、CREATE PROCEDURE 语句运行部署脚本。如果您没有部署脚本,请吸取教训并创建一个。从 VS Server Explorer 开发应用程序在展会上进行的演示中非常有用,但在实际部署中则不然。

Does you hosting provider support attachable databases (ie. AttachDBFileName?). Most hosting providers don't allow this. The error message seems to indicate pretty strongly that that's the case. Attacheable databases are an Express only feature, and hosting providers offer one database per account on a shared instance, I didn't hear of providers offering Express instances per account.

So you are going to connect to your designated database on the shared instance, created for you by your provider, not to the MDF file you copied. In order to deploy your schema now you need to run a deployment script with the various CREATE TABLE, CREATE VIEW, CREATE PROCEDURE statements that build your application schema. If you do not have a deployment script, then learn your lesson and create one. Developing applications from the VS Server Explorer is great in demos done at shows, but not the trenches doing real deployments.

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