用于连接到 SQL Server 的 Web.config 条目
好吧,我正在尝试将应用程序的连接从 Oracle 更改为 SQL Server。我在 web.config 中有这个。
<compilation debug="true">
<assemblies>
...
<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
...
</assemblies>
</compilation>
当
<appSettings>
<add key="DatabaseProvider" value="Test.App.Oracle8i"/>
<add key="SmtpUser" value="[email protected]"/>
<add key="SmtpPassword" value="testpassword"/>
<add key="SmtpDefaultSender" value="[email protected]"/>
<add key="SmtpHost" value="mail.example.com"/>
<add key="SmtpPort" value="25"/>
<add key="EnableSsl" value="False"/>
</appSettings>
我更改这些应用程序的这些值时,这
<connectionStrings>
<add name="CnString" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=loCALHOST)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));User Id=TESTUSER;Password=TESTPASSWORD;"/>
</connectionStrings>
将不会运行并标记错误。
<compilation debug="true">
<assemblies>
...
<add assembly="System.Data.SqlClient, Version=10.50.1600, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
...
</assemblies>
</compilation>
最后
<appSettings>
<add key="DatabaseProvider" value="Test.App.SqlServer"/>
<add key="SmtpUser" value="[email protected]"/>
<add key="SmtpPassword" value="testpassword"/>
<add key="SmtpDefaultSender" value="[email protected]"/>
<add key="SmtpHost" value="mail.example.com"/>
<add key="SmtpPort" value="25"/>
<add key="EnableSsl" value="False"/>
</appSettings>
一个
<connectionStrings>
<add name="CnString" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=MSSQLSERVER)));Initial Catalog=TESTDATABASE;User Id=TESTUSER;Password=TESTPASSWORD;"/>
</connectionStrings>
或
<connectionStrings>
<add name="CnString" providerName="System.Data.SqlClient" connectionString="Data Source=(local)\\MSSQLSERVER;Initial Catalog=TESTDATABASE;User Id=TESTUSER;Password=TESTPASSWORD;"/>
</connectionStrings>
我不明白的是应该制作线条。
<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add key="DatabaseProvider" value="Test.App.Oracle8i"/>
<add name="CnString" connectionString="Data Source=**(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=loCALHOST)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)))**;User Id=TESTUSER;Password=TESTPASSWORD;"/>
Well I'm trying to change the connection of my application from Oracle to SQL Server. I have this in web.config.
<compilation debug="true">
<assemblies>
...
<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
...
</assemblies>
</compilation>
and
<appSettings>
<add key="DatabaseProvider" value="Test.App.Oracle8i"/>
<add key="SmtpUser" value="[email protected]"/>
<add key="SmtpPassword" value="testpassword"/>
<add key="SmtpDefaultSender" value="[email protected]"/>
<add key="SmtpHost" value="mail.example.com"/>
<add key="SmtpPort" value="25"/>
<add key="EnableSsl" value="False"/>
</appSettings>
and this
<connectionStrings>
<add name="CnString" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=loCALHOST)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));User Id=TESTUSER;Password=TESTPASSWORD;"/>
</connectionStrings>
When I change these values for these application will not run and mark errors.
<compilation debug="true">
<assemblies>
...
<add assembly="System.Data.SqlClient, Version=10.50.1600, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
...
</assemblies>
</compilation>
and
<appSettings>
<add key="DatabaseProvider" value="Test.App.SqlServer"/>
<add key="SmtpUser" value="[email protected]"/>
<add key="SmtpPassword" value="testpassword"/>
<add key="SmtpDefaultSender" value="[email protected]"/>
<add key="SmtpHost" value="mail.example.com"/>
<add key="SmtpPort" value="25"/>
<add key="EnableSsl" value="False"/>
</appSettings>
and the last
<connectionStrings>
<add name="CnString" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=MSSQLSERVER)));Initial Catalog=TESTDATABASE;User Id=TESTUSER;Password=TESTPASSWORD;"/>
</connectionStrings>
or
<connectionStrings>
<add name="CnString" providerName="System.Data.SqlClient" connectionString="Data Source=(local)\\MSSQLSERVER;Initial Catalog=TESTDATABASE;User Id=TESTUSER;Password=TESTPASSWORD;"/>
</connectionStrings>
I do not understand is supposed to make the lines.
<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add key="DatabaseProvider" value="Test.App.Oracle8i"/>
<add name="CnString" connectionString="Data Source=**(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=loCALHOST)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)))**;User Id=TESTUSER;Password=TESTPASSWORD;"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
连接到 SQL Server 所需的唯一两行是:
和
(如果是 .NET 2.0/3.x,则更改版本和 publicKeyToken)
然后使用:
就是这样。
在 .NET 中,不存在诸如
System.Data.SqlClient, Version=10.50.1600, ...
这样的程序集。 SqlClient 是标准 .NET Framework 发行版的一部分。例如,System.Data.SqlClient.SqlConnection:
The only 2 lines you need to connect to SQL Server is:
and
(change version and publicKeyToken in case of .NET 2.0/3.x)
Then use:
That's it.
In .NET there is no such assembly as
System.Data.SqlClient, Version=10.50.1600, ...
. SqlClient is the part of standart .NET Framework distribution.For example, System.Data.SqlClient.SqlConnection: