ASP.NET MVC3:连接字符串 - 不支持关键字:'initial catalog' [英] ASP.NET MVC3: Connection string - Keyword not supported: 'initial catalog'

查看:2162
本文介绍了ASP.NET MVC3:连接字符串 - 不支持关键字:'initial catalog'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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尝试将其更改为服务器/数据库,但仍然有相同的错误。我在哪里错了?

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:目录。

推荐答案

请检查: 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);

这篇关于ASP.NET MVC3:连接字符串 - 不支持关键字:'initial catalog'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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