将 Linq-to-Sql 与 SQL Server 2008 R2 结合使用

发布于 2024-12-18 02:40:27 字数 349 浏览 0 评论 0原文

我已经在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

給妳壹絲溫柔 2024-12-25 02:40:27

进入您的设计器文件,查看属性,然后找到您的设计器正在使用的连接字符串。

然后深入研究 dbml 文件,找到 DataContext 的默认构造函数正在使用的配置设置,并确保该设置的连接字符串与设计器中的连接字符串相同。

您可以在这里找到设计器的连接信息:

在此处输入图像描述

这就是我的默认构造函数的样子:

    public DataClasses1DataContext() : 
            base(global::Junk.Properties.Settings.Default.ZoomieRestConnectionString, mappingSource)
    {
        OnCreated();
    }

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:

enter image description here

And this is what my default constructor looks like:

    public DataClasses1DataContext() : 
            base(global::Junk.Properties.Settings.Default.ZoomieRestConnectionString, mappingSource)
    {
        OnCreated();
    }
醉态萌生 2024-12-25 02:40:27

由于您没有提供代码,因此可能很难想象到底出了什么问题。无论如何,这里是 Linq to SQL 连接的代码。与你的相匹配

SqlConnection dataConnection = new SqlConnection();
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "YourSeverName";
builder.InitialCatalog = "YourDatabase";
builder.IntegratedSecurity = true;
dataConnection.ConnectionString = builder.ConnectionString;

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

SqlConnection dataConnection = new SqlConnection();
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = "YourSeverName";
builder.InitialCatalog = "YourDatabase";
builder.IntegratedSecurity = true;
dataConnection.ConnectionString = builder.ConnectionString;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文