[英]SQL Server 2012 connection string works fine in classic ASP (VBScript) but doesn't work in ASP.NET C# project
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. 我有一个SQL Server数据库 ,我的确从经典的ASP项目对SQL Server进行操作。 I needed to do some other stuffs into the same DB from another project which is written in ASP.NET C# .
我需要从另一个用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 ).
我确实在主机提供商提供的连接字符串中使用了主机地址(例如,主机地址为sqlxx.123xxx \\ inst_xyz )。 They also provided an IP with a port to connect the DB, which only works in SQL Server Management Studio .
他们还为IP提供了一个用于连接数据库的端口,该端口仅在SQL Server Management Studio中可用。 In the webconfig of C# project if I use the IP then it connects from my local dev machine.
在C#项目的webconfig中,如果我使用IP,则它从我的本地开发机连接。 But it doesn't work after deploying to hosting.
但是在部署到托管后它不起作用。
Again, if I use sqlxx.123xxx\\inst_xyz as host address in classic ASP then it works. 同样,如果我在经典ASP中使用sqlxx.123xxx \\ inst_xyz作为主机地址,则它可以工作。 The IP doesn't work here.
IP在这里不起作用。 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 ?
我的问题是,主机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.
建立与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.
验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)**
(提供者:SQL网络接口,错误:26-指定服务器/实例时出错)**
Try one of these two: 尝试以下两种方法之一:
\\
in the connection string, to \\\\
: "sqlxx.123xxx\\\\inst_xy" \\
双击为\\\\
:“ sqlxx.123xxx \\\\ inst_xy” I'm thinking the backslash needs escaping. 我认为反斜杠需要转义。
Put this: 把这个:
<add key="myCon" value="Server=this_my_host;database=dbname;User Id=myuser;Password=dbpass;"/>
and Remove <connectionStrings>
. 并删除
<connectionStrings>
。
If you are connecting with your Remote host then you must use the <appSettings>
not the <connectionStrings>
string. 如果要与远程主机连接,则必须使用
<appSettings>
而不是<connectionStrings>
字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.