用于连接到 SQL Server 的 Web.config 条目

发布于 2024-11-03 04:32:12 字数 3398 浏览 4 评论 0原文

好吧,我正在尝试将应用程序的连接从 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 技术交流群。

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

发布评论

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

评论(1

ζ澈沫 2024-11-10 04:32:12

连接到 SQL Server 所需的唯一两行是:

<connectionStrings>
    <add name="CnString" providerName="System.Data.SqlClient" connectionString="Data Source=(local)\\MSSQLSERVER;Initial Catalog=TESTDATABASE;User Id=TESTUSER;Password=TESTPASSWORD;"/>
</connectionStrings>

<assemblies>
    <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>

(如果是 .NET 2.0/3.x,则更改版本和 publicKeyToken)

然后使用:

SqlConnection connection = new SqlConnection("CnString");
// ...

就是这样。


在 .NET 中,不存在诸如 System.Data.SqlClient, Version=10.50.1600, ... 这样的程序集。 SqlClient 是标准 .NET Framework 发行版的一部分。

例如,System.Data.SqlClient.SqlConnection

Namespace:  System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

The only 2 lines you need to connect to SQL Server is:

<connectionStrings>
    <add name="CnString" providerName="System.Data.SqlClient" connectionString="Data Source=(local)\\MSSQLSERVER;Initial Catalog=TESTDATABASE;User Id=TESTUSER;Password=TESTPASSWORD;"/>
</connectionStrings>

and

<assemblies>
    <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>

(change version and publicKeyToken in case of .NET 2.0/3.x)

Then use:

SqlConnection connection = new SqlConnection("CnString");
// ...

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:

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