简体   繁体   English

Asp.Net与SQL Server和Asp.net Linq应用程序

[英]Asp.Net With SQL Server And Asp.net Linq Application

I have an application that uses linq-to-sql with Sql Server Express 2008. When I use the DBML file in a separate DAL project and refer to it to my web project, on execute Sql Server shows this error: 我有一个将linq-to-sql与Sql Server Express 2008一起使用的应用程序。当我在单独的DAL项目中使用DBML文件并将其引用到我的Web项目时,在执行Sql Server时显示此错误:

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 when I use the DBML in my web project, debugging is without any problem. 但是,当我在Web项目中使用DBML时,调试就没有任何问题。 But on IIS in Windows 7 64bit i get: 但是在Windows 7 64bit的IIS上我得到:

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接)

Do these two errors have the same cause? 这两个错误的起因是否相同? Is the connection string not correct? 连接字符串不正确吗?

I'd suspect that in the first case you have the connection string in the DAL project and not in your web project (where it belongs). 我怀疑在第一种情况下,您在DAL项目中拥有连接字符串,而在您的Web项目中却没有连接字符串。 Make sure you copy it to the web.config of your web project. 确保将其复制到Web项目的web.config

In the second case I think that that the machine hosting IIS tries to connect to the database on your own machine. 在第二种情况下,我认为承载IIS的计算机尝试连接到您自己计算机上的数据库。 If so, check the exception: make sure your SQL Express instance is configured to allow remote connections, that the IP protocol is enabled (named pipes if for local traffic), and that your machine is accessible to the IIS machine. 如果是这样,请检查以下异常:确保将SQL Express实例配置为允许远程连接,启用IP协议(如果用于本地通信,则命名为管道),并且IIS计算机可以访问您的计算机。

I think, Your connections string is wrong. 我认为,您的连接字符串错误。

dont worry. 不用担心。

check your dbml's designer.cs file. 检查您的dbml的designer.cs文件。 in which you will find '<YourDBMLFile>DataContext() ' Constructor. 在其中,您将找到'<YourDBMLFile>DataContext() '构造函数。

and Change your Connection string. 并更改您的连接字符串。 make sure your connectionstring is correct. 确保您的connectionstring字符串正确。

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

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