VB6应用程序可以连接到SQL Server,但.NET应用程序不能 [英] VB6 applications can connect to SQL Server, but .NET applications can't

查看:150
本文介绍了VB6应用程序可以连接到SQL Server,但.NET应用程序不能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的系统使用VB6旧版应用程序和较新的.NET应用程序的组合。应用程序部署到我们的客户端,并从终端服务器框中运行应用程序,SQL Server数据库运行在不同的框上。



VB6应用程序正常工作,而所有.NET应用程序每次启动时都会失败(尝试连接数据库以读取配置信息),并显示错误:


System.Data.SqlClient.SqlException:与SQL Server建立连接时发生与网络相关或实例特定的错误。服务器未找到或无法访问。验证实例名称是否正确,并将SQL Server配置为允许远程连接。 (提供商:TCP提供程序,错误:0 - 连接尝试失败,因为连接方在一段时间后没有正确响应,或连接的主机无法响应,建立连接失败。)


这是非常奇怪的事情:我在C#中创建了一个测试.NET应用程序,它复制了.NET应用程序使用的确切连接字符串 - 我部署了一个显示所使用的实际连接字符串的应用程序以及测试应用程序



VB6连接字符串(作品): Provider = SQLOLEDB; Data Source = servername; Initial Catalog = databasename; User ID = username; Password = password;



连接字符串(两个工作不起作用): Data Source = servername; Initial Catalog = databasename; User ID = username; Password = password; Application Name =ourappname



我们的其他客户都没有经历过这个问题相同的二进制文件,这告诉我.NET应用程序如何与这个特定客户端的系统进行交互是一个问题。



我应该采取哪些步骤来排除/修复这个问题问题?在这一点上我真的很失落。我希望有人以前看过这个问题;在Google上找不到任何相关内容。







  • 这两个框都是Windows Server 2008 R2 SP1在VMWare上运行,并且位于同一个域中

  • 这两个框都运行ESET NOD32;

  • SQL Server是2008 R2 RTM的默认实例(同一个框架上也有2008和2008 R2的命名实例)

  • 应用程序(和我的测试应用程序)是.NET 4.0

  • 应用程序使用SQL登录进行身份验证(是的,我检查了失败的应用程序正在使用的密码是否正确)

  • 一些.NET应用程序使用不同的代码来执行应用程序启动,但它们都显示相同的错误

  • 某些.NET应用程序是C#,有些是VB,有些是混合的(VB应用程序,C#核心程序集)

  • 我已经尝试修复.NET 4.0安装

  • 我已经尝试重新启动两个框

  • 我已经尝试部署源二进制文件,以便我们的部署子系统被绕过(以防其导致某种损坏)

  • 我在本地编译的测试应用程序与原始文件相同,它是通过构建的团队系统


解决方案

我发现这个行为通常有几个主要原因:


  1. SQL Server未配置为侦听特定的连接类型。要确定这一点,在SQL计算机上打开SQL Server配置管理器,单击SQL Server网络配置,然后单击MSSQLServer协议。验证TCP / IP是否启用。


  2. SQL Server不允许远程连接(如果其他应用程序正在连接,那显然不是问题) p>


  3. 客户端计算机未配置为使用SQL Server支持的协议与SQL Server通信,或客户端计算机输入的配置信息不正确。要验证这一点,请从运行提示中运行cliconfg,并确保启用相应的协议,并且Alias选项卡中没有任何冲突的别名。我通常添加一个专门为连接字符串配置的机器名称与适当的IP地址,以防万一有DNS问题(至少用于测试)。


  4. 由于VB6客户端工作,并且.Net客户端不会有64位与32位访问有问题。如果您的应用程序是为64位或任何CPU编译的,则可以尝试使用32位版本来查看是否解决了访问。如果是这样,那么这很可能是64位SQL客户端配置问题。



Our system uses a combination of VB6 legacy applications and newer .NET applications. The applications are deployed to our clients, and they run the applications from a Terminal Server box, with the SQL Server database running on a different box.

The VB6 applications work fine, while all of the .NET applications fail on startup (trying to connect to the database to read configuration information) every time with the error:

System.Data.SqlClient.SqlException: 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: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

Here's the really weird thing: I created a test .NET application in C# that replicates the exact connection string used by the .NET applications -- I deployed an instrumented version of one of the applications that displays the actual connection string used -- and the test app works.

VB6 connection string (works): Provider=SQLOLEDB;Data Source=servername;Initial Catalog=databasename;User ID=username;Password=password;

.NET connection string (both works and doesn't work): Data Source=servername;Initial Catalog=databasename;User ID=username;Password=password;Application Name="ourappname"

None of our other clients have experienced this issue with the same binaries, which tells me it's a problem with how the .NET applications are interacting with this particular client's system.

What steps should I take to troubleshoot/fix this issue? I'm really at a loss at this point. I'm hoping someone else has seen this issue before; I couldn't find anything relevant on Google.


  • Both boxes are Windows Server 2008 R2 SP1 running on VMWare, and are in the same domain
  • Both boxes run ESET NOD32; disabling didn't change anything
  • SQL Server is a default instance of 2008 R2 RTM (there are also 2008 and 2008 R2 named instances on the same box)
  • The applications (and my test app) are .NET 4.0
  • The application uses a SQL login to authenticate (yes, I checked that the password being used by the failing apps is correct)
  • Some of the .NET applications use different code to do application startup, yet they all exhibit the same error
  • Some of the .NET applications are C#, some are VB, some are mixed (VB apps, C# core assemblies)
  • I've tried repairing the .NET 4.0 install
  • I've tried rebooting both boxes
  • I've tried deploying the source binaries such that our deployment subsystem was circumvented (in case it was causing corruption of some kind)
  • The instrumented application which I compiled locally experiences the same behaviour as the original, which was built via Team System

解决方案

I have found that there are usually a few primary causes of this behavior:

  1. SQL Server is not configured to listen for the specific connection type. To determine this, open SQL Server Configuration Manager on the SQL Machine, click the SQL Server Network COnfiguraiton and then Protocols for MSSQLServer. Verify that TCP/IP is enabled.

  2. SQL Server not allowing remote connections (if other apps are connecting, then this is obviously not a problem).

  3. The client machine is not configured to talk to SQL Server using SQL Server's supported protocols OR the the client machine has incorrect configuration information entered. To verify this, run cliconfg from the Run... prompt and ensure the appropriate protocols are enabled and that there aren't any conflicting aliases in the Alias tab. I usually add one specifically for the machine name configured in the connection string with the appropriate IP address in case there is a DNS issue (at least for testing).

  4. Since VB6 clients work and .Net clients don't there could be an issue with 64-bit versus 32-bit access. If your app is compiled for 64-bit or Any CPU, you may try a 32-bit build to see if that resolves the access. If so, then this is most likely a 64-bit SQL Client configuration issue.

这篇关于VB6应用程序可以连接到SQL Server,但.NET应用程序不能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆