SQL Server Express的MVC6连接字符串 [英] MVC6 Connection Strings for SQL Server Express

查看:85
本文介绍了SQL Server Express的MVC6连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC5实体框架已经很长时间了,连接字符串在web.config中看起来像这样:

I was using MVC5 Entity Framework for a long time with connection string in web.config that look like this:

<connectionStrings>
    <add name="GuestContext" 
         connectionString="Data Source=DAVESQLSERVER\SQLEXPRESS;Initial Catalog=NexDec12;Integrated Security=False;User ID=sa;Password=changeME!;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

我试图在appsettings.json文件中弄清楚该如何做.我正在使用Rick Anderson的教程

I am trying to figure out how to do this in the appsettings.json file. I am learning MVC6 using Rick Anderson's tutorial here.

我不是要在VS或IIS10中使用内置的SQL Server,而是要连接到外部SQL Server Express.我已经尝试过了,但是它不起作用,说用户sa的登录名无效(因此它试图使用正确的用户名?)我感觉它没有使用正确的密码,但是我不知道如何为新的MVC6 json配置格式构造一个连接字符串.

Rather than use the built in SQL Server in VS or IIS10 I want to connect to my external SQL Server Express. I have tried this but it doesn't work, says the login is invalid for user sa (so it's trying to use the correct username?) I feel like it isn't using the correct password but I don't know how to construct a connnection string for the new MVC6 json config format.

我尝试过:

"Data": {
    "DefaultConnection": {
      "ConnectionString": "Server=DAVESQLSERVER\\SQLEXPRESS;Database=MovieTut;Trusted_Connection=True;MultipleActiveResultSets=true; Integrated Security=false;User ID=sa;Password=changeME!"
    }

推荐答案

我会为您的config.json建议一个不同的结构,就像这样(注意两个连接声明中的ConnectionString元素")

I would recommend a different structure to your config.json, like so (notice "ConnectionString element in both connection declarations)

已编辑,可将格式添加到代码中

EDITED to add format to the code

"Data": {
    "DefaultConnection": {
        "ConnectionString": "Server=.;Database=MyDb;Trusted_Connection=True;MultipleActiveResultSets=true"
    },
"EmployeeContext": {
        "ConnectionString": "Server=.;Database=Manish_Database;Trusted_Connection=True;MultipleActiveResultSets=true"
    }
}

这篇关于SQL Server Express的MVC6连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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