SQL Server 2014に接続しようとしています。システムチームは最近2014年にアップグレードしました。変わったのは、SQL Server Management Studioを使用してODBC、Telnetに接続できることです。これは単なるC#の問題です。さらに、この正確なプログラムは別のサーバーでコンパイル/リリースとして実行されます。私のシステムでは、デバッグ(または完全にコンパイル/リリース)を使用して実行されていません。C#プログラムでSQL Serverに接続できませんが、システムに接続することができます
私はドキュメントで確認 - 無効すべてのファイアウォール、STPは、サーバーをチェックしていた...灘
エラー:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
私のC#コード:
namespace SQLTest
{
class Program
{
static void Main(string[] args)
{
string connectionString = ConfigurationManager.ConnectionStrings["SQLConn"].ConnectionString;
string OrganizationSqlStr = @"SELECT * FROM school";
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(OrganizationSqlStr, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.Write(reader["School_ID"] + " | ");
Console.Write(reader["title"] + "\n\r");
}
Console.ReadKey();
}
}
}
app.config
を:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings>
<add name="SQLConn"
connectionString="server=SERVER;database=DATABASE;uid=USERNAME;password=PASSWORD"/>
</connectionStrings>
</configuration>
明白な疑問やご意見でしたが、あなたの接続文字列で 'DATABASE'、' USERNAME'、 'PASSWORD'を実際の値に置き換えましたか? –
えええええええええええええええええええええええええええええええええええと、 :) –
@HarporSydneyあなたはSQLアカウントを介してSQLサーバーに接続しているか、Windowsの資格情報を使用していますか? SQLアカウントを使用している場合、データベースは混在認証を許可するように構成されていますか? – user1666620