如何将 ASP.NET 配置连接到 SQL 服务器而不是 SQL Server Express?
How to connect ASP.NET config to SQL Server instead of SQL Server Express?
我使用 aspnet_regsql.exe
配置了我的 SQL 服务器数据库。一切都很好。然后我在 web.config
文件中添加了新的连接字符串:
<connectionStrings>
<clear />
<remove name="LocalSqlServer" />
<add name="SQLConnectionString"
connectionString="Provider=ProvName;Server=Sname;Database=dbName;Uid=user; Pwd=pWord" />
</connectionStrings>
当我尝试从网站访问数据库时出现错误:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
Source Error:
我通过 Visual Studio 在 IIS 上 运行 这个站点 10. 知道我遗漏了什么步骤吗?
您的代码正在查找名为 "LocalSqlServer" 的连接字符串,但您正在添加名为 "SQLConnectionString".
的连接字符串
将其更改为:
<add name="LocalSqlServer" connectionString="Provider=ProvName;Server=Sname;Database=dbName;Uid=user; Pwd=pWord" />
<add name="LocalSqlServer" connectionString="Data Source=.;Initial Catalog=DBName;Uid=user;Pwd=pWord" provider="System.Data.SqlClient"/>
类似上面的方法应该可以。
在您的所有配置和代码 (.cs?) 文件中搜索短语 "LocalSqlServer"。它在其他地方被引用...不仅仅是连接字符串配置区域。
"name" 属性在代码的其他地方用于查找实际的连接字符串。
我喜欢 Agent Ransack 在文件中查找特定字符串。
当您找到另一个参考时,您可以将其替换为 "MySuperSpecialConnectionStringName"(如下所示,对原始代码的更改)。
我使用 aspnet_regsql.exe
配置了我的 SQL 服务器数据库。一切都很好。然后我在 web.config
文件中添加了新的连接字符串:
<connectionStrings>
<clear />
<remove name="LocalSqlServer" />
<add name="SQLConnectionString"
connectionString="Provider=ProvName;Server=Sname;Database=dbName;Uid=user; Pwd=pWord" />
</connectionStrings>
当我尝试从网站访问数据库时出现错误:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.Source Error:
我通过 Visual Studio 在 IIS 上 运行 这个站点 10. 知道我遗漏了什么步骤吗?
您的代码正在查找名为 "LocalSqlServer" 的连接字符串,但您正在添加名为 "SQLConnectionString".
的连接字符串将其更改为:
<add name="LocalSqlServer" connectionString="Provider=ProvName;Server=Sname;Database=dbName;Uid=user; Pwd=pWord" />
<add name="LocalSqlServer" connectionString="Data Source=.;Initial Catalog=DBName;Uid=user;Pwd=pWord" provider="System.Data.SqlClient"/>
类似上面的方法应该可以。
在您的所有配置和代码 (.cs?) 文件中搜索短语 "LocalSqlServer"。它在其他地方被引用...不仅仅是连接字符串配置区域。
"name" 属性在代码的其他地方用于查找实际的连接字符串。
我喜欢 Agent Ransack 在文件中查找特定字符串。
当您找到另一个参考时,您可以将其替换为 "MySuperSpecialConnectionStringName"(如下所示,对原始代码的更改)。