我正在尝试使用c#查询某些odbc oracle
个对象,但我不知道如何发送odbc credentials
。我可以连接到数据库但是当我尝试查询对象时,访问会向我发出一个请求ODBC Oracle credentials
的对话框。
public void ConnectToAccess()
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Program Files (x86)\\DB\\Version1\\data\\access\\System L\\today.mdb; Jet OLEDB:System Database=C:\\Program Files (x86)\\DB\\Version1\\data\\access\\System\\system.mdw;" + "User ID=informix;Password=;");
"" /wrkgrp "C:\Program Files (x86)\DB\Version1\data\access\System\system.mdw" /cmd dsn=lcssl1
try
{
string sql = "SELECT * FROM Users";
myConn.Open();
DataSet ds = new DataSet();
using (System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter(sql, myConn))
{
adapter.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
//Of course, before addint the datagrid to the hosting form you need to
//
//set position, location and other useful properties.
//
//Why don't you create the DataGrid with the designer and use that instance instead?
}
}
catch (Exception ex)
{
MessageBox.Show("Failed to connect to data source");
}
finally
{
myConn.Close();
}
}