SQL Server Express的MVC6连接字符串

编程入门 行业动态 更新时间:2024-10-27 16:29:15
本文介绍了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连接字符串

本文发布于:2023-10-28 13:11:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1536730.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   Server   SQL   Express

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!