连接字符串 - 不支持关键字:“初始目录”
我正在使用 Webmatrix.data 的数据库实体来创建数据库连接,但它不喜欢我的连接字符串。我从 MVC ASP.net 运行它。
我尝试将其更改为服务器/数据库,但仍然出现相同的错误。我哪里出错了?
using (var db = Database.OpenConnectionString(@"Data Source=MY-HP\Serv;Initial Catalog=MyDBSQL;User ID=sa;Password=password"))
{
var items = db.Query("SELECT * FROM TaskPriority");
}
异常详细信息:System.ArgumentException:不支持关键字:“初始目录”。
I am using Webmatrix.data's Database entity to create a database connection, however it doesnt like my connection string. I am running it from MVC ASP.net.
Ive tried changing it to server / database, but still errors the same. Where am I going wrong?
using (var db = Database.OpenConnectionString(@"Data Source=MY-HP\Serv;Initial Catalog=MyDBSQL;User ID=sa;Password=password"))
{
var items = db.Query("SELECT * FROM TaskPriority");
}
Exception Details: System.ArgumentException: Keyword not supported: 'initial catalog'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
检查此处: Database.OpenConnectionString 方法(字符串、字符串)
尝试将提供程序名称指定为第二个参数,来自 MSDN 示例:
check here: Database.OpenConnectionString Method (String, String)
try to specify the provider name as second parameter, from the MSDN example:
啊啊啊啊啊!!!!!!
这是我第二次遇到这个问题,grrr - 浪费了几个小时。
错误:
服务器在处理请求时遇到错误。异常消息是“不支持关键字:'初始目录;MyDatabase;数据源'。”。有关更多详细信息,请参阅服务器日志。异常堆栈跟踪是:
堆栈跟踪:
这是我的错误连接字符串:
看起来不错吧? 错误
最终我在这里发现了分号:
为了纠正它,我使用了等号:
正确的连接字符串:
ARRRRHHHHHH!!!!!
This is the second time I've run into this, grrrh - wasted hours on it.
Error:
The server encountered an error processing the request. The exception message is 'Keyword not supported: 'initial catalog;MyDatabase;data source'.'. See server logs for more details. The exception stack trace is:
Stacktrace:
This was my faulty connection string:
<add name="Production" connectionString="Password=Secret;Persist Security Info=True;User ID=MyUserID;Initial Catalog;MyDatabase;Data Source=aquickborwnfoxjumpedover.us-west-2.rds.amazonaws.com,1433" providerName="System.Data.SqlClient" />
Looks good right? WRONG
Eventually I spotted the semi-colon here:
To correct it, I used an equal sign:
The correct connection string:
<add name="ConnString" connectionString="Password=Secret;Persist Security Info=True;User ID=MyUserID;Initial Catalog=MyDatabase;Data Source=aquickborwnfoxjumpedover.us-west-2.rds.amazonaws.com,1433" providerName="System.Data.SqlClient" />
我在 IdentityServer 快速入门之一中遇到了错误。
必须替换
为
using
因为显然我的数据库是 Microsoft SQL Server 而不是 SQLite。
I ran into the error in one of the IdentityServer quickstarts.
Had to replace
With
Using
Because obviously my DB was a Microsoft SQL Server and not SQLite.
您可以使用以下代码
配置文件:
cshtmlfile:
You can use the below code
Config file :
cshtmlfile :
对我来说,我收到此错误是因为我使用的是模板化解决方案。我不知道的是,该模板仅安装了对 sqlite 的支持。我必须安装
Microsoft.EntityFrameworkCore.SqlServer
并将代码中的调用从UseSqlite
更改为UseSqlServer
。For me I was getting this error because I was using a templated solution. Unbeknownst to me the template only installed support for sqlite. I had to install
Microsoft.EntityFrameworkCore.SqlServer
and change the calls in my code fromUseSqlite
toUseSqlServer
.您需要检查您的连接字符串。
我收到错误是因为我的连接字符串中有 db(而不是“数据库”)。
更新上述连接字符串(db 到数据库)应该可以解决问题。下面是工作连接字符串。
You need to check your connection string.
I received the error because I had db(instead of 'Database') in my connection string.
Updating the above connection string(db to Database) should solve the problem. Below is the working connection string.
我建议:
你可以清楚地检查你的连接字符串格式,特别是“和”。就我而言,这是:
I suggest:
You can check your connection string format clearly especialy " and ". In my case this is: