C# 需要在连接字符串上指定提供者吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/556014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 08:02:17  来源:igfitidea点击:

Provider needed to be specify on a connectionstring?

c#sqldatabaseconnection-string

提问by PlayKid

I have a very funny problem on my application, I get an error as follow: System.ArgumentException: An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'.

我的应用程序有一个非常有趣的问题,我收到如下错误: System.ArgumentException:ConnectionString 中未指定 OLE DB 提供程序。例如,'Provider=SQLOLEDB;'。

However, when I tried to speicify the provider on my connection as Provider=SQLOLEDB.1 or Provider=SQLOLEDB, then I get another error saying invalid keyword 'Provider'.

但是,当我尝试将连接上的提供程序指定为 Provider=SQLOLEDB.1 或 Provider=SQLOLEDB 时,我收到另一个错误,提示关键字“Provider”无效。

But one thing I noticed, the computer that I am targeting to had 2 different database system, will that cause this error?

但是我注意到一件事,我的目标计算机有 2 个不同的数据库系统,这会导致这个错误吗?

Any idea how to solve this problem?

知道如何解决这个问题吗?

Regards

问候

采纳答案by Joannes Vermorel

Assuming that you are using ADO.NET, if you want to use distinct database systems, then you need to correct the DbConnection too, not only the connection string.

假设您使用的是 ADO.NET,如果您想使用不同的数据库系统,那么您还需要更正 DbConnection,而不仅仅是连接字符串。

Note that you can't use an SqlConnectionfor OLEDB, you need to use System.Data.OleDb.OleDbConnectioninstead.

请注意,您不能SqlConnection为 OLEDB使用 an ,您需要使用它System.Data.OleDb.OleDbConnection来代替。

回答by PlayKid

Looks like your missing some bits of the connection string - try these

看起来您缺少连接字符串的一些位 - 试试这些

General Connection String:

一般连接字符串:

strConnect = _T("Provider=sqloledb;Data Source=MyServerName;"
        "Initial Catalog=MyDatabaseName;"
        "User Id=MyUsername;Password=MyPassword;");

Named Instance Connection String:

命名实例连接字符串:

strConnect = _T("Provider=sqloledb;Data Source=MyServerName\MyInstanceName;"
    "Initial Catalog=MyDatabaseName;User Id=MyUsername;Password=MyPassword;");

Trusted Security:

可信安全:

strConnect = _T("Provider=sqloledb;Data Source=MyServerName;"
        "Initial Catalog=MyDatabaseName;"
        "Integrated Security=SSPI;");

From here http://www.codeproject.com/KB/database/connectionstrings.aspx#OLEDB SqlServer

从这里http://www.codeproject.com/KB/database/connectionstrings.aspx#OLEDB SqlServer