我需要連接遠程Oracle服務器
代碼如下:
//得到連接字符串
private string DataCon()
{
string conUser = "abc", conPassword = "abc", conDataSource = "TEST", conServer = "10.134.189.53",conPort="1521";
string strCon = "Provider=OraOLEDB.Oracle.1;Persist Security Info=True"+
";User ID=" + conUser + ";Password=" + conPassword+
";Data Source='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + conServer + ")(PORT=" + conPort + ")))(CONNECT_DATA=(SERVICE_NAME=" + conDataSource + ")))'";
return strCon;
}
//點擊按鈕事件,訪問數據庫
private void button1_Click(object sender, EventArgs e)
{
string tempstrCon = this.DataCon();
string tempstrCom = "select * from table";
OleDbConnection tempmyConn = new OleDbConnection(tempstrCon);
DataSet tempmyDataSet = new DataSet();
OleDbDataAdapter tempmyCommand = new OleDbDataAdapter(tempstrCom, tempmyConn);
tempmyCommand.Fill(tempmyDataSet);
tempmyConn.Open();
dataGridView1.DataSource = tempmyDataSet;
OleDbCommand tempCommand = new OleDbCommand(tempstrCom, tempmyConn);
tempCommand.ExecuteNonQuery();
tempmyConn.Close(); }報錯信息如下:
{"The 'OraOLEDB.Oracle.1' provider is not registered on the local machine."}什么原因?
我之前有Delphi的程序連接數據庫可以OK
所以我的Oracle應該沒有問題
以上是何解?
代碼如下:
//得到連接字符串
private string DataCon()
{
string conUser = "abc", conPassword = "abc", conDataSource = "TEST", conServer = "10.134.189.53",conPort="1521";
string strCon = "Provider=OraOLEDB.Oracle.1;Persist Security Info=True"+
";User ID=" + conUser + ";Password=" + conPassword+
";Data Source='(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + conServer + ")(PORT=" + conPort + ")))(CONNECT_DATA=(SERVICE_NAME=" + conDataSource + ")))'";
return strCon;
}
//點擊按鈕事件,訪問數據庫
private void button1_Click(object sender, EventArgs e)
{
string tempstrCon = this.DataCon();
string tempstrCom = "select * from table";
OleDbConnection tempmyConn = new OleDbConnection(tempstrCon);
DataSet tempmyDataSet = new DataSet();
OleDbDataAdapter tempmyCommand = new OleDbDataAdapter(tempstrCom, tempmyConn);
tempmyCommand.Fill(tempmyDataSet);
tempmyConn.Open();
dataGridView1.DataSource = tempmyDataSet;
OleDbCommand tempCommand = new OleDbCommand(tempstrCom, tempmyConn);
tempCommand.ExecuteNonQuery();
tempmyConn.Close(); }報錯信息如下:
{"The 'OraOLEDB.Oracle.1' provider is not registered on the local machine."}什么原因?
我之前有Delphi的程序連接數據庫可以OK
所以我的Oracle應該沒有問題
以上是何解?
{
String conString = "Data Source=DB;Persist Security Info=True;User ID=;Password=;Unicode=True"; OracleConnection myCon = new OracleConnection(conString);
return myCon;
}OracleConnection OracleCon = this.getOraCon();
OracleCon.Open();OleDbDataAdapter da = new OleDbDataAdapter("select * from table", OleDbCon);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = new DataTable();
dt = ds.Tables[0];
dataGridView1.DataSource = dt;
我有用你的方法試了不過提示出錯{"An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'."}
你的连接串,Provider=OraOLEDB.Oracle.1,改为Provider=OraOLEDB.Oracle试试,
应该是Provider串名不合适的问题。