连接字符串 - 不支持关键字:“初始目录”

发布于 2024-12-16 02:17:15 字数 436 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

亚希 2024-12-23 02:17:15

检查此处: Database.OpenConnectionString 方法(字符串、字符串)

尝试将提供程序名称指定为第二个参数,来自 MSDN 示例:

var connectionString = "Data Source=.\\SQLExpress;Initial Catalog=SmallBakery;Integrated Security=True";

var providerName = "System.Data.SqlClient";

var db = Database.OpenConnectionString(connectionString, providerName);

check here: Database.OpenConnectionString Method (String, String)

try to specify the provider name as second parameter, from the MSDN example:

var connectionString = "Data Source=.\\SQLExpress;Initial Catalog=SmallBakery;Integrated Security=True";

var providerName = "System.Data.SqlClient";

var db = Database.OpenConnectionString(connectionString, providerName);
极度宠爱 2024-12-23 02:17:15

啊啊啊啊啊!!!!!!
这是我第二次遇到这个问题,grrr - 浪费了几个小时。

错误:

服务器在处理请求时遇到错误。异常消息是“不支持关键字:'初始目录;MyDatabase;数据源'。”。有关更多详细信息,请参阅服务器日志。异常堆栈跟踪是:

堆栈跟踪:

在 System.Data.Common.DbConnectionOptions.ParseInternal(哈希表
可解析、字符串连接字符串、布尔构建链、哈希表
同义词、布尔值firstKey) at
System.Data.Common.DbConnectionOptions..ctor(字符串连接字符串,
Hashtable 同义词、布尔值使用OdbcRules) at
System.Data.SqlClient.SqlConnectionString..ctor(字符串
连接字符串)位于
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(字符串
连接字符串、DbConnectionOptions 之前)位于
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey
key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions&
用户连接选项)位于
System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey
键)在
System.Data.SqlClient.SqlConnection.set_ConnectionString(字符串值)
在 System.Data.SqlClient.SqlConnection..ctor(字符串连接字符串,
SqlCredential凭证)

这是我的错误连接字符串:

>

看起来不错吧? 错误

最终我在这里发现了分号:

初始目录;MyDatabase

为了纠正它,我使用了等号:

初始目录=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:

at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable
parsetable, String connectionString, Boolean buildChain, Hashtable
synonyms, Boolean firstKey) at
System.Data.Common.DbConnectionOptions..ctor(String connectionString,
Hashtable synonyms, Boolean useOdbcRules) at
System.Data.SqlClient.SqlConnectionString..ctor(String
connectionString) at
System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String
connectionString, DbConnectionOptions previous) at
System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey
key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions&
userConnectionOptions) at
System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey
key) at
System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
at System.Data.SqlClient.SqlConnection..ctor(String connectionString,
SqlCredential credential)

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:

Initial Catalog;MyDatabase

To correct it, I used an equal sign:

Initial Catalog=MyDatabase

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" />

小…红帽 2024-12-23 02:17:15

我在 IdentityServer 快速入门之一中遇到了错误。

必须替换

services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));

services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

using

Microsoft.EntityFrameworkCore.SqlServer

因为显然我的数据库是 Microsoft SQL Server 而不是 SQLite。

I ran into the error in one of the IdentityServer quickstarts.

Had to replace

services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));

With

services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

Using

Microsoft.EntityFrameworkCore.SqlServer

Because obviously my DB was a Microsoft SQL Server and not SQLite.

ぃ双果 2024-12-23 02:17:15

您可以使用以下代码

配置文件:

   <connectionStrings>
   <add name="con" connectionString="Data Source=ServerName;Initial Catalog=master;Integrated Security=SSPI;" providerName="System.Data.SqlClient"></add>
  </connectionStrings>

cshtmlfile:

var db = Database.Open("con");

var selecteddata = db.Query("select * from movie");

You can use the below code

Config file :

   <connectionStrings>
   <add name="con" connectionString="Data Source=ServerName;Initial Catalog=master;Integrated Security=SSPI;" providerName="System.Data.SqlClient"></add>
  </connectionStrings>

cshtmlfile :

var db = Database.Open("con");

var selecteddata = db.Query("select * from movie");
深白境迁sunset 2024-12-23 02:17:15

对我来说,我收到此错误是因为我使用的是模板化解决方案。我不知道的是,该模板仅安装了对 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 from UseSqlite to UseSqlServer.

浅唱々樱花落 2024-12-23 02:17:15

您需要检查您的连接字符串。

我收到错误是因为我的连接字符串中有 db(而不是“数据库”)。

 "DevConnection": "server=DEL1-XX-XXXX;db=DonationDb;user=sa;password=XXXX"

更新上述连接字符串(db 到数据库)应该可以解决问题。下面是工作连接字符串。

 "DevConnection":"server=DEL1-XX-XXXX;Database=DonationDb;user=sa;password=QwerXXXX"

You need to check your connection string.

I received the error because I had db(instead of 'Database') in my connection string.

 "DevConnection": "server=DEL1-XX-XXXX;db=DonationDb;user=sa;password=XXXX"

Updating the above connection string(db to Database) should solve the problem. Below is the working connection string.

 "DevConnection":"server=DEL1-XX-XXXX;Database=DonationDb;user=sa;password=QwerXXXX"
杯别 2024-12-23 02:17:15

我建议:


  1. 你可以清楚地检查你的连接字符串格式,特别是“和”。就我而言,这是:


  1. 您可以尝试再次使用EF生成db。

I suggest:


  1. You can check your connection string format clearly especialy " and ". In my case this is:


  1. You may try generate db by EF again.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文