SQL Server 2012连接字符串在经典ASP(VBScript)中工作正常,但在ASP.NET C#项目中不起作用

时间:2022-01-07 04:27:29

I have a scenario just like below:

我有一个场景如下:

I have a SQL Server Database and I do make operations to SQL server from my classic asp project. I needed to do some other stuffs into the same DB from another project which is written in ASP.NET C#. I did use a host address in connection string which was provided by hosting provider(Say, the host address is sqlxx.123xxx\inst_xyz). They also provided an IP with a port to connect the DB, which only works in SQL Server Management Studio. In the webconfig of C# project if I use the IP then it connects from my local dev machine. But it doesn't work after deploying to hosting.

我有一个SQL Server数据库,我从我的经典asp项目中对SQL服务器进行操作。我需要从另一个用ASP.NET C#编写的项目中将一些其他东西放到同一个DB中。我确实在托管服务提供商提供的连接字符串中使用了主机地址(比如说,主机地址是sqlxx.123xxx \ inst_xyz)。他们还为IP提供了一个连接数据库的端口,该端口仅适用于SQL Server Management Studio。在C#项目的webconfig中如果我使用IP,那么它从我的本地开发机器连接。但是在部署到托管后它不起作用。

Again, if I use sqlxx.123xxx\inst_xyz as host address in classic ASP then it works. The IP doesn't work here. My question is, host sqlxx.123xxx\inst_xyz works in classic ASP, IP works in ASP.NET C# in local IIS, but what will be the host for ASP.NET C# in hosting server ?

再次,如果我在经典ASP中使用sqlxx.123xxx \ inst_xyz作为主机地址,那么它的工作原理。知识产权在这里不起作用。我的问题是,主机sqlxx.123xxx \ inst_xyz在经典ASP中工作,IP在本地IIS中的ASP.NET C#中工作,但是在主机服务器中ASP.NET C#的主机是什么?

Please Note that, classic ASP project is in the main domain and ASP.NET C# project is in a sub domain of the main domain.

请注意,经典ASP项目位于主域,ASP.NET C#项目位于主域的子域中。

If I use either of the hosts(sqlxx.123xxx\inst_xyz or IP), I get an error which states exactly like below :

如果我使用任一主机(sqlxx.123xxx \ inst_xyz或IP),我会收到一个错误,其状态如下:

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 - 查找指定的服务器/实例时出错)**

2 个解决方案

#1


0  

Put this:

<add key="myCon" value="Server=this_my_host;database=dbname;User Id=myuser;Password=dbpass;"/>

and Remove <connectionStrings>.

并删除

If you are connecting with your Remote host then you must use the <appSettings> not the <connectionStrings> string.

如果要与远程主机连接,则必须使用 而不是 字符串。

#2


1  

Try one of these two:

尝试以下两种方法之一:

  1. Put a @ in front of your connection string: @"sqlxx.123xxx\inst_xy"
  2. 在你的连接字符串前放一个@:@“sqlxx.123xxx \ inst_xy”

  3. Double the \ in the connection string, to \\: "sqlxx.123xxx\\inst_xy"
  4. 将连接字符串中的\加倍到\\:“sqlxx.123xxx \\ inst_xy”

I'm thinking the backslash needs escaping.

我认为反斜杠需要逃避。

#1


0  

Put this:

<add key="myCon" value="Server=this_my_host;database=dbname;User Id=myuser;Password=dbpass;"/>

and Remove <connectionStrings>.

并删除

If you are connecting with your Remote host then you must use the <appSettings> not the <connectionStrings> string.

如果要与远程主机连接,则必须使用 而不是 字符串。

#2


1  

Try one of these two:

尝试以下两种方法之一:

  1. Put a @ in front of your connection string: @"sqlxx.123xxx\inst_xy"
  2. 在你的连接字符串前放一个@:@“sqlxx.123xxx \ inst_xy”

  3. Double the \ in the connection string, to \\: "sqlxx.123xxx\\inst_xy"
  4. 将连接字符串中的\加倍到\\:“sqlxx.123xxx \\ inst_xy”

I'm thinking the backslash needs escaping.

我认为反斜杠需要逃避。