将 Linq-to-Sql 与 SQL Server 2008 R2 结合使用
我已经在 VS2008 中为 SQL Server 2008 R2 创建了一些 Linq-to-SQL 类对象。
我在服务器资源管理器中添加了到它的连接。然后将存储过程添加到设计图面。
但是当我运行该应用程序时,它会产生以下错误:
发生网络相关或特定于实例的错误 建立与 SQL Server 的连接。找不到服务器或 无法访问。验证实例名称是否正确 SQL Server 配置为允许远程连接。 (提供者:SQL 网络接口,错误:26 - 定位服务器/实例时出错 指定)”
根据谷歌搜索的博客,我已经为远程连接启用了 TCP/IP 和命名管道。
I have created some Linq-to-SQL classes object in VS2008 for SQL Server 2008 R2 fine.
I added a connection to it in server explorer. Then add a stored proc to design surface.
But when I run the app it produces this error:
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)"
I have enabled TCP/IP and Named Pipes for remote connections according to a googled blog.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
进入您的设计器文件,查看属性,然后找到您的设计器正在使用的连接字符串。
然后深入研究 dbml 文件,找到 DataContext 的默认构造函数正在使用的配置设置,并确保该设置的连接字符串与设计器中的连接字符串相同。
您可以在这里找到设计器的连接信息:
这就是我的默认构造函数的样子:
Go into your designer file, look in the properties, and find the connection string your designer is using.
Then dig into your dbml file, find the config setting the default constructor of your DataContext is using, and make sure that connection string that setting has is the same as the one from your designer.
Here's where you can find the designer's connection info:
And this is what my default constructor looks like:
由于您没有提供代码,因此可能很难想象到底出了什么问题。无论如何,这里是 Linq to SQL 连接的代码。与你的相匹配
Since you haven't provided the code, its presumably hard to think what going wrong underneath. Anyways here is the code for Linq to SQL connection. Match it with yours