无法将连接字符串传递给 OleDbConnection
更新:错误是由名为 OleDbConnection 的类隐藏 OleDbConnection 构造函数引起的,因此不提供重载方法。
我正处于学习如何使用 ole 数据库连接的早期阶段,但是我立即遇到了问题。尽管有一个重载方法来创建 OleDbConnection 连接,但它根本不允许我传入连接字符串。
这就是我正在尝试的。
private OleDbConnection _myConnection = null;
public bool CreateConnection()
{
try
{
_myConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["OracleDefault"].ConnectionString);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return true;
}
现在似乎没有任何问题,但是我收到一条错误消息,指出该方法有 0 个参数,但使用 1 个参数调用。我见过无数的例子表明它是以这种方式完成的,但由于某种原因它不允许我这样做。有什么想法吗?
更新:删除了分号,因为它不应该出现在我发布的示例中,但这不是问题。它根本不接受任何形式的字符串。
UPDATE: Error was caused by a class named the OleDbConnection hiding the OleDbConnection constructors and therefore not presenting the overload method.
I am in the early stages of learning how to use ole database connections however I have run into a probem straight away. Despite there being an overload method to create an OleDbConnection connection it simply wont allow me to pass a connection string in.
Heres what I am trying.
private OleDbConnection _myConnection = null;
public bool CreateConnection()
{
try
{
_myConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["OracleDefault"].ConnectionString);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return true;
}
Now there doesn't seem to be anything wrong with that however I get an error saying that the method has 0 parameters but is invoked with 1 argument. I have seen countless examples showing it done in this way but for some reason it just won't let me do it. Any ideas?
UPDATE: Removed the semi colon as it wasnt supposed to be in the example I posted however this is not the issue. It simply won't accept any form of string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需删除 ;在 ["OracleDefault"].ConnectionString 之后。
Just remove the ; after ["OracleDefault"].ConnectionString.
使用
而不是因为
构造函数包含需要字符串的重载。
Use
instead of
as the constructor contains an overload that require string.
更新:错误是由名为 OleDbConnection 的类隐藏 OleDbConnection 构造函数引起的,因此不提供重载方法。
UPDATE: Error was caused by a class named the OleDbConnection hiding the OleDbConnection constructors and therefore not presenting the overload method.