我想从我的ASP.NET应用程序使用SQL Server本机客户端连接到SQL Server 2012.目前,我有一个现有的连接字符串连接使用odbc和工作正常.appSettingsadd key=StagingConnect value=Integrated Security=True;Initia...
我想从我的ASP.NET应用程序使用SQL Server本机客户端连接到SQL Server 2012.目前,我有一个现有的连接字符串连接使用odbc和工作正常.
<appSettings>
<add key="StagingConnect"
value="Integrated Security=True;Initial Catalog=Staging;Data Source=AUBDSG01.AUYA.NET\INST1"/>
</appSettings>
当我尝试如下时,代码抛出异常
<add key="StagingConnect"
value="Provider=SQLNCLI11;Integrated Security=True;Initial Catalog=Staging;Data Source=AUBDSG01.AUYA.NET\INST1"/>
例外:
System.Web.HttpUnhandledException (0x80004005): Exception of type ‘System.Web.HttpUnhandledException’ was thrown.
System.ArgumentException: Keyword not supported: ‘provider’.
at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
at System.Data.ProviderBase.DbConnectionFactory
如何修改此连接字符串,以便它应通过SQL Server本机客户端11进行连接
解决方法:
由于我的连接字符串没有进入< appSettings>,因此不确定您之前是如何使用它的.它进入一个单独的< connectionStrings>部分. providerName是一个元素,不是字符串本身的一部分.
这是一个例子
<connectionStrings>
<clear />
<add name="xxx" providerName="System.Data.SqlClient" connectionString="Server=(local);Database=yyy;User=zzz;Password=123;MultipleActiveResultSets=True" />
</connectionStrings>
希望这可以帮助.
本文标题为:c# – ASP.NET web.config中SQL Server本机客户端的连接字符串
- C# 解决在Dictionary中使用枚举的效率问题 2023-04-10
- NPOI实现两级分组合并功能(示例讲解) 2022-11-28
- Unity实现虚拟键盘 2023-04-09
- c#实现输出的字符靠右对齐的示例 2022-11-28
- C#使用IronPython库调用Python脚本 2023-06-14
- c#调用c语言dll需要注意的地方 2023-04-10
- 详解C# winform ListView的基本操作 2023-05-16
- 详解C#对路径...的访问被拒绝解决过程 2023-03-28
- C#中winform中panel重叠无法显示问题的解决 2023-02-02
- 基于C# 写一个 Redis 数据同步小工具 2023-02-08