简体   繁体   English

将SQL Server数据库连接到ASP.NET应用程序版本

[英]Connecting SQL Server database to ASP.NET application release

I have an ASP.NET application using Entity Framework. 我有一个使用实体框架的ASP.NET应用程序。 I'm trying to release it on the hosting, but I get following errors: 我正在尝试在主机上发布它,但是出现以下错误:

[Win32Exception (0x80004005): The system cannot find the file specified] [Win32Exception(0x80004005):系统找不到指定的文件]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. [SqlException(0x80131904):建立与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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)] (提供者:SQL网络接口,错误:52-无法找到本地数据库运行时安装。验证是否正确安装了SQL Server Express并启用了本地数据库运行时功能。)]

I set the connection string as shown on the hosting website and created database. 我设置了托管网站上显示的连接字符串,并创建了数据库。 How should I configure this to get rid of this error? 我应该如何配置它来消除此错误?

Exception due to your web application is not able to connect SQLSERVER instance. 由于您的Web应用程序无法连接SQLSERVER实例,因此发生异常。 Following are options to resolve the problem: 以下是解决问题的选项:

  1. Check if your service is running up 检查您的服务是否正在运行

Go to All Programs > Microsoft SQL Server 2012 > Configuration Tools > SQL Server Configuration Manager > SQL Server Services Check to make sure SQL Server service status is Running. 转到所有程序> Microsoft SQL Server 2012>配置工具> SQL Server配置管理器> SQL Server服务检查以确保SQL Server服务状态为“正在运行”。

or 要么

Open run command console(Windows + R) then type services.msc. 打开运行命令控制台(Windows + R),然后键入services.msc。 You will all services in your system and check SqlServer (Sqlexpress) service is running mode. 您将在系统中使用所有服务,并检查SqlServer(Sqlexpress)服务是否处于运行模式。

  1. Make sure your database engine is configured to accept remote connections 确保您的数据库引擎配置为接受远程连接

Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration Click on Surface Area Configuration for Services and Connections Select the instance that is having a problem > Database Engine > Remote Connections Enable local and remote connections Restart instance using services.msc in run command window(discussed in #1) 开始>所有程序> SQL Server 2005>配置工具> SQL Server外围应用配置单击服务和连接的外围应用配置选择有问题的实例>数据库引擎>远程连接启用本地和远程连接使用服务重新启动实例。运行命令窗口中的msc(在#1中讨论)

  1. Enable TCP/IP in SQL Server Configuration 在SQL Server配置中启用TCP / IP

Go to All Programs >> Microsoft SQL Server 2012 > Configuration Tools >> SQL Server Configuration Manager >> Select TCP/IP 转到所有程序>> Microsoft SQL Server 2012>配置工具>> SQL Server配置管理器>>选择TCP / IP

Right Click on TCP/IP >> Click on Enable 右键单击TCP / IP >>单击启用

Then restart the sqlserver service using services.msc in run command window(discussed in #1) 然后在运行命令窗口中使用services.msc重新启动sqlserver服务(在#1中讨论)

Lastly you need to check that it might be server firewall setting because sometimes firewall blocks incoming request from other servers. 最后,您需要检查这可能是服务器防火墙设置,因为有时防火墙会阻止来自其他服务器的传入请求。 And also check you are providing correct connection string means username, password, server etc. 并检查您提供的连接字符串是否正确,包括用户名,密码,服务器等。

Thank You.. 谢谢..

<connectionStrings>
        <add name="conn2" connectionString="Data   Source=192.?.?.?\your_db_instance;Initial Catalog=your_db_schema;Integrated Security=False;User ID=your_db_login;Password=??????" providerName="System.Data.SqlClient"/>
</connectionStrings>

As you are able to connect from SQL SMS, try to connect with the same remote parameters from Server Explorer window in Visual Studio as well. 由于能够从SQL SMS连接,因此也尝试从Visual Studio的“服务器资源管理器”窗口中使用相同的远程参数进行连接。 Click "add connection" on "Data Connections": Add Connection in Server Explorer . 在“数据连接”上单击“添加连接”: 在Server Explorer中添加连接 After the connection being created, get the connection string from the properties window by right clicking on the connection object. 创建连接后,右键单击连接对象,从属性窗口中获取连接字符串。 Use this connection string in the hosted web.config file. 在托管的web.config文件中使用此连接字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM