[英]How to connect to SQL Server 2008 with asp net core 2?
i am learning a asp.net core 2, i am new at microsoft technology which is using Entity Framework and using Package Manager Console, what i do here is i am following this tutorial https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/model 我正在学习asp.net核心2,我是使用实体框架和程序包管理器控制台的Microsoft技术的新手,我在这里的工作是遵循本教程https://docs.microsoft.com/zh-cn / ASPNET /核心/教程/剃刀页/模型
which is teach me about connection to database, but there is just connection to localdb, which is provided like this : 它教会了我有关数据库连接的知识,但是只有与localdb的连接,其提供方式如下:
appsettings.json : appsettings.json:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionStrings": {
"MovieContext": "Server=(localdb)\\mssqllocaldb;Database=Movie-1;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}
but i want to connect to my SQL Server 2008 R2 which i installed it on my local server 但是我想连接到我在本地服务器上安装的SQL Server 2008 R2
here is my connection string look like : 这是我的连接字符串,如下所示:
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionStrings": {
"MovieContext": "Server=localhost\\SQLEXPRESS;Database=Movie-1;MultipleActiveResultSets=true"
}
}
then i run a command "Update-Database" in Package Manager Console, then i got this error : 然后在程序包管理器控制台中运行命令“ Update-Database”,然后出现此错误:
A network-related or instance-specific error occurred while establishing a connection to SQL Server.
建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible.
服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
(提供者:SQL网络接口,错误:26-指定服务器/实例时出错)
but i can connect to my Sql server 2008 with SQL Studio management perfectly, which is i just put the servername : localhost and the default login. 但是我可以使用SQL Studio管理完美地连接到我的Sql Server 2008,这就是我只需要输入服务器名:localhost和默认登录名。 What do i miss there?
我在那里想念什么?
I just found out that actually i don't need instance for the connection string, so here is how my appsettings.json looks like 我刚刚发现实际上我不需要连接字符串的实例,所以这是我的appsettings.json的样子
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionStrings": {
"MovieContext": "Server=localhost;Database=Movie-1;User Id=root;Password=12345;MultipleActiveResultSets=true"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.