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

时间:2020-12-17 03:30:50

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:

我有一个应用程序在Sql Server Express 2008中使用linq-to-sql。当我在一个单独的DAL项目中使用DBML文件并将其引用到我的web项目时,在execute Sql Server上显示如下错误:

A network-related or instance-specific error occurred while establishing a connection to 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. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

在建立到SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名是否正确,并将SQL Server配置为允许远程连接。(提供者:SQL网络接口,错误:26 -错误定位服务器/实例指定)

But when I use the DBML in my web project, debugging is without any problem. But on IIS in Windows 7 64bit i get:

但是当我在web项目中使用DBML时,调试是毫无问题的。但在Windows 7 64位的IIS上,我得到:

A network-related or instance-specific error occurred while establishing a connection to 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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

在建立到SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名是否正确,并将SQL Server配置为允许远程连接。(提供程序:命名管道提供程序,错误:40 -无法打开到SQL Server的连接)

Do these two errors have the same cause? Is the connection string not correct?

这两个错误有相同的原因吗?连接字符串不正确吗?

2 个解决方案

#1


1  

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). Make sure you copy it to the web.config of your web project.

我怀疑,在第一种情况下,您在DAL项目中有连接字符串,而在您的web项目中没有(它所属的地方)。一定要把它复制到网络上。web项目的配置。

In the second case I think that that the machine hosting IIS tries to connect to the database on your own machine. 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.

在第二种情况下,我认为主机托管IIS尝试连接到您自己机器上的数据库。如果有,请检查异常:确保您的SQL Express实例被配置为允许远程连接、IP协议被启用(如果是本地通信,则命名管道)以及IIS机器可以访问。

#2


0  

I think, Your connections string is wrong.

我认为,你的连接字符串是错误的。

dont worry.

不要担心。

check your dbml's designer.cs file. in which you will find '<YourDBMLFile>DataContext()' Constructor.

检查你的dbml的设计师。cs文件。其中您将找到' DataContext()'构造函数。

and Change your Connection string. make sure your connectionstring is correct.

并更改连接字符串。确保您的connectionstring是正确的。

#1


1  

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). Make sure you copy it to the web.config of your web project.

我怀疑,在第一种情况下,您在DAL项目中有连接字符串,而在您的web项目中没有(它所属的地方)。一定要把它复制到网络上。web项目的配置。

In the second case I think that that the machine hosting IIS tries to connect to the database on your own machine. 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.

在第二种情况下,我认为主机托管IIS尝试连接到您自己机器上的数据库。如果有,请检查异常:确保您的SQL Express实例被配置为允许远程连接、IP协议被启用(如果是本地通信,则命名管道)以及IIS机器可以访问。

#2


0  

I think, Your connections string is wrong.

我认为,你的连接字符串是错误的。

dont worry.

不要担心。

check your dbml's designer.cs file. in which you will find '<YourDBMLFile>DataContext()' Constructor.

检查你的dbml的设计师。cs文件。其中您将找到' DataContext()'构造函数。

and Change your Connection string. make sure your connectionstring is correct.

并更改连接字符串。确保您的connectionstring是正确的。