我有以下代码,它连接到我的数据库并从表中检索一些数据:
string connectionString = "Data Provider=SQLOLEDB;Data Source=myserver;Initial Catalog=Db;Integrated Security=FALSE;user=zh;pwd=zh12;";
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "SELECT [Location], [URL], [TAGS] FROM [Db].[dbo].[BOOKINGTABLE]";
command.CommandType = CommandType.Text;
using (OleDbDataReader reader = command.ExecuteReader())
{
menu_ul_1.DataSource = reader;
menu_ul_1.DataBind();
}
}
我遇到了以下错误:
异常细节:System.ArgumentException: 在 ConnectionString 中未指定 OLE DB 提供程序。 例如,可以使用“Provider=SQLOLEDB;”。
当我将连接字符串行更改为:
string connectionString = "Provider=SQLOLEDB;Data Source=myserver;Initial Catalog=Db;Integrated Security=FALSE;user=zh;pwd=zh12;";
I get the following error:
Exception Details: System.Data.OleDb.OleDbException: No error message available, result code: DB_E_ERRORSOCCURRED(0x80040E21).
Source Error:
Line 23: using (OleDbConnection connection = new OleDbConnection(connectionString))
Line 24: {
Line 25: connection.Open();
Line 26:
Line 27: OleDbCommand command = new OleDbCommand();
我该如何解决这个问题?
我的Web.config文件中有以下行:
<add key="ConnStringTEST" value="Data Source=myserver;Initial Catalog=Db;Integrated Security=FALSE;user=zh;pwd=zh12;" />
如何在我的C#代码中使用上述代码行?
Provider=SQLNCLI10
和Provider=SQLNCLI.1
之类的东西,但不知道为什么。它只是起作用了。 - Erran Morad