我有一個非標準本地Oracle DB來,我可以用我的SQLDeveloper 使用連接進行連接:SQL連接C#
username = system
password = orcl
hostname = localhost
port = 1521
SID = ORCL
但是當我試圖做到這一點的代碼
try
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "localhost";
builder.InitialCatalog = "HR_ORCL";
builder.UserID = "system";
builder.Password = "orcl";
string connectionString = "Server=(local);Database=HR_ORCL;User ID=system;Password=orcl";
using (SqlConnection connection = new SqlConnection())
{
connection.ConnectionString = builder.ConnectionString;
connection.Open();
Console.WriteLine("State: {0}", connection.State);
Console.WriteLine("ConnectionString: {0}",
connection.ConnectionString);
}
}
catch(Exception error)
{
System.Console.WriteLine(error.Message);
}
我得到一個錯誤
"provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL server"
我到底做錯了什麼?
你的問題是? –
我添加了一個錯誤。 – Ghostleg
您正在使用SQL服務器類連接到Oracle數據庫。您應該爲Visual Studio安裝ODAC和ODT,並使用Oracle託管驅動程序。 http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html –