使用的OleDbConnection.Open()甚至聯繫SQL服務器
"Provider=SQLOLEDB;Data Source=localhost;User ID=foo;password=bar;Database=CodeLists;Pooling=true;Min Pool Size=20;Max Pool Size=30;"
我得到以下堆棧跟蹤
System.Data連接字符串之前拋出一個「沒有錯誤消息可用」錯誤.OleDb.OleDbException:否提供 錯誤消息,結果代碼: -2147024770(0x8007007E)。在System.Data.OleDb.OleDbServicesWrapper.GetDataSource在 System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString 構造,OleDbConnection的連接)
(OleDbConnectionString 構造,DataSourceWrapper & datasrcWrapper)在 System.Data.OleDb。 OleDbConnectionFactory.CreateConnection(DbConnectionOptions 選項,對象poolGroupProviderInfo, 池類DBConnectionPool,的DbConnection owningObject)在在 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(的DbConnection owningConnection, DbConnectionPoolGroup poolGroup)System.Data.ProviderBase.DbConnectionFactory.GetConnection(的DbConnection owningConnection)在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(的DbConnection outerConnection,DbConnectionFactory connectionFactory的)在 System.Data.OleDb.OleDbConnection.Open()
即使我將服務器URL從本地主機更改爲無效的hkfjhuidhf,我也會得到此錯誤,所以我認爲這是服務器上與OleDb連接/設置和/或MDAC有關的問題。
服務器是運行最新Service Pack的Windows Server 2003,MDAC是2.8 SP2。
我正在使用的代碼是:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void run_Click(object sender, EventArgs e)
{
output.Text = string.Empty;
try
{
OleDbConnection connection;
try
{
connection = new OleDbConnection(conString.Text);
}
catch (Exception ex)
{
MessageBox.Show("Error creating connection");
put(ex.ToString());
return;
}
OleDbCommand command;
try
{
command = connection.CreateCommand();
}
catch (Exception ex)
{
MessageBox.Show("Error creating command");
put(ex.ToString());
return;
}
command.CommandType = CommandType.Text;
command.CommandText = "select top 10 * from " + table.Text;
if (connection.State != ConnectionState.Open)
connection.Open();
OleDbDataReader reader;
try
{
reader = command.ExecuteReader();
if (reader.HasRows)
{
string @out = string.Empty;
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
@out += reader[i] + ", ";
}
}
put(@out);
}
reader.Close();
}
catch (Exception ex)
{
put(ex.ToString());
}
finally
{
connection.Close();
}
}
catch (Exception ex)
{
put(ex.ToString());
}
}
private void put(string message)
{
output.Text += message+Environment.NewLine;
}
}
,並在connection.Open()
沒有人有任何想法,這屬於過?我已經從inf文件中重新安裝了MDAC,但是我已經閱讀了一些關於.Net代碼的文章,其中討論了關於MDAC 2.8的SP2。
任何和所有的輸入是非常值得歡迎的。
您使用SQL Server Express嗎? – James 2009-08-21 10:45:23