简体   繁体   English

如何使用ASP Net Core 2连接到SQL Server 2008?

[英]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.

相关问题 如何从在容器中运行的 ASP.NET 核心应用程序连接到具有集成安全性的 Windows 服务器上的 SQL 服务器 - How to connect from ASP.NET Core application running in a container to SQL Server on Windows Server with Integrated Security 如何将 ASP.NET Core 5 MVC 项目连接到 Supabase 数据库而不是 SQL 服务器? - How to connect ASP.NET Core 5 MVC project to Supabase database instead of SQL Server? 如何连接 ASP.NET Core 的 docker 镜像(代码优先)和 SQL 服务器 - How to connect docker images of ASP.NET Core (code first) and SQL server 如何使用ASP.NET Core API与Microsoft SQL Server连接 - How to connect with microsoft sql sever with ASP.NET Core API ASP.NET MVC 3应用程序无法连接到AWS实例上的SQL Server 2008实例 - ASP.NET MVC 3 app cannot connect to SQL server 2008 instance on AWS instance 如何从托管在 **1&1 Ionos** 托管服务器中的 ASP.NET Core 2.2 连接 MS SQL Server 数据库? - How to connect MS SQL Server database from ASP.NET Core 2.2 hosted in **1&1 Ionos** hosting server? 如何连接到现有数据库? .NET Core API和SQL Server 2012 - How to connect to existing database? .NET Core API & SQL Server 2012 .NET 核心 - 无法连接 SQL 服务器 - .NET Core - not able to connect SQL Server 如何连接到ASP.Net中不同域中的SQL Server? - How to connect to a SQL Server in a different domain in ASP.Net? ASP.NET 核心如何上传图片到SQL服务器数据库? - ASP.NET Core how to upload image to SQL Server database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM