调试vb.net执行数据库函数调用远程sql服务器

发布于 2024-12-05 04:28:13 字数 1281 浏览 4 评论 0原文

在 VWD 2010 Express 中工作时,

我有一个带有以下连接字符串的 aspx.vb 文件:

   Protected Function getPasswordLength() As Integer
        Dim conn As New SqlConnection("Data Source=localhost;database=MyDB;Integrated Security=true")
        Dim cmd As SqlCommand = conn.CreateCommand()

        cmd.CommandText = "select dbo.getPWLen() ;"
        conn.Open()
        getPasswordLength = CInt(cmd.ExecuteScalar())
        conn.Close()

    End Function

当代码位于 Web 服务器上/与 SQLServer 并置时,此文件有效。 但是,当我想调试时,我必须复制到服务器。我希望能够在我的开发计算机上“就地调试”,并且仅定期将文件复制到生产计算机。从技术上讲,生产机器目前尚未投入生产,但这不是重点。

无论如何,我遵循了以下说明: http://weblogs.asp.net/nannettethacker/archive/2008/02/17/creating-a-database-connection-to-a-remote-sql-server-database-within-visual- web-developer.aspx

我现在可以在另一台计算机上看到远程数据库、函数等(从开发计算机上运行的 VWD)。

但是,我认为我应该能够使用 ctrl-F5 在开发计算机上本地执行相同的代码,但出现以下错误:

-- **“/”应用程序中的服务器错误。

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

我正在做的事情应该可行吗?如果是这样,你知道我做错了什么吗?

Working in VWD 2010 Express

I have an aspx.vb file with the following connection string:

   Protected Function getPasswordLength() As Integer
        Dim conn As New SqlConnection("Data Source=localhost;database=MyDB;Integrated Security=true")
        Dim cmd As SqlCommand = conn.CreateCommand()

        cmd.CommandText = "select dbo.getPWLen() ;"
        conn.Open()
        getPasswordLength = CInt(cmd.ExecuteScalar())
        conn.Close()

    End Function

This works when the code is on the web server / which is collocated with the SQLServer.
However, when I want to debug, I have to copy to the server. I would like to be able to "debug in place" on my development machine and only copy files to the production machine periodically. Technically the production machine is not in production at the moment, but that's beside the point.

Anyway, I followed the following instruction: http://weblogs.asp.net/nannettethacker/archive/2008/02/17/creating-a-database-connection-to-a-remote-sql-server-database-within-visual-web-developer.aspx

I can now see the remote database, functions, etc. on the other machine (from the VWD running on the development machine).

However, I thought I should then be able to execute this same code locally on the development machine using ctrl-F5, but I get the following error:

--
**Server Error in '/' Application.

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)**

Should what I'm doing be possible? If so, any ideas what I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文