连接字符串-不支持关键字:“初始目录” [英] Connection string - Keyword not supported: 'initial catalog'

查看:403
本文介绍了连接字符串-不支持关键字:“初始目录”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Webmatrix.data的数据库实体创建数据库连接,但是它不喜欢我的连接字符串。我从MVC ASP.net运行它。

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");
        }

异常详细信息:System.ArgumentException:不支持关键字:'initial目录。

推荐答案

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

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

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);

这篇关于连接字符串-不支持关键字:“初始目录”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆