0
你好,我的連接有問題時,我將我的代碼轉移到另一臺電腦。在它的原始計算機中,它工作正常。但在另一臺電腦上卻說連接錯誤。我確定該電腦上的新連接字符串是正確的,所以我認爲它與配置管理器有關。 其它PC具有的Visual Studio的相同版本和SQL Express的c#配置管理器
應用程序配置代碼:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="MPnew.Properties.Settings.MARISCHELLdatabaseConnectionString1" connectionString="Data Source=BENJOPC\SQLEXPRESS;Initial Catalog=MARISCHELLdatabase;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name ="cnn" connectionString="Data Source=BENJOPC\SQLEXPRESS;Initial Catalog=MARISCHELLdatabase;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
連接代碼:
using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnn"].ConnectionString))
{
if (cnn.State == ConnectionState.Closed)
cnn.Open();
// continue code
}
它高度依賴於你想要發生的事情。那臺名爲'BENJOPC'的計算機是否需要從任何計算機連接到SQLEXPRESS實例,然後您必須確保SqlExpress實例正在偵聽您的網絡接口並且防火牆已打開。如果你想和本地用戶建立一個本地連接,使用sqlexpress實例替換'BENJOPC',它可能會幫助你搜索你得到的確切異常。你不是第一個遇到這個問題的人 – rene