我有以下代码连接到我的数据库并从表中检索一些数据:
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();
}
}
我收到以下错误:
Exception Details: System.ArgumentException: An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'.
当我将连接字符串行更改为:
string connectionString = "Provider=SQLOLEDB;Data Source=myserver;Initial Catalog=Db;Integrated Security=FALSE;user=zh;pwd=zh12;";
我收到以下错误:
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# 代码中使用上面的行吗?
经过多次故障排除后,我找出了它不起作用的原因。我像这样重写了字符串:
string cString = "Provider=sqloledb;Data Source=myserver;Initial Catalog=mydatabase;User Id=myid;Password=mypassword;";
如果其他人遇到同样的问题,这就像一个魅力。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)