gpt4 book ai didi

c# - ASP.NET web.config 中 SQL Server native 客户端的连接字符串

转载 作者:太空狗 更新时间:2023-10-30 00:48:12 24 4
gpt4 key购买 nike

我想从我的 ASP.NET 应用程序使用 SQL Server native 客户端连接到 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"/>

异常(exception):

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 native 客户端 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 native 客户端的连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48825136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com