SQL Server 2012 连接字符串在经典 ASP (VBScript) 中工作正常,但在 ASP.NET C# 项目中不起作用
SQL Server 2012 connection string works fine in classic ASP (VBScript) but doesn't work in ASP.NET C# project
我有如下场景:
我有一个 SQL 服务器数据库,我确实从我的 经典 asp 对 SQL 服务器进行操作 项目。我需要从另一个用 ASP.NET C# 编写的项目中对同一个数据库执行一些其他操作。我确实在托管服务提供商提供的连接字符串中使用了主机地址(例如,主机地址是 sqlxx.123xxx\inst_xyz)。他们还提供了一个 IP 和一个连接数据库的端口,它只在 SQL Server Management Studio 中有效。在 C# 项目的 webconfig 中,如果我使用 IP,那么它会从我的本地开发机器连接。但是部署到hosting后就不行了
同样,如果我在经典 ASP 中使用 sqlxx.123xxx\inst_xyz 作为主机地址,那么它就可以工作。 IP在这里不起作用。 我的问题是,主机 sqlxx.123xxx\inst_xyz 在经典 ASP 中工作,IP 在本地 IIS 中的 ASP.NET C# 中工作,但是 [=42= 的主机是什么] 托管服务器中的 C# ?
请注意,经典ASP项目在主域中,ASP.NETC#项目在主域的子域中。
如果我使用主机(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)**
试试这两个之一:
- 在你的连接字符串前加上一个@:@"sqlxx.123xxx\inst_xy"
- 将连接字符串中的
\
加倍到 \
:"sqlxx.123xxx\inst_xy"
我认为反斜杠需要转义。
把这个:
<add key="myCon" value="Server=this_my_host;database=dbname;User Id=myuser;Password=dbpass;"/>
并删除 <connectionStrings>
.
如果您要与远程主机连接,则必须使用 <appSettings>
而不是 <connectionStrings>
字符串。
我有如下场景:
我有一个 SQL 服务器数据库,我确实从我的 经典 asp 对 SQL 服务器进行操作 项目。我需要从另一个用 ASP.NET C# 编写的项目中对同一个数据库执行一些其他操作。我确实在托管服务提供商提供的连接字符串中使用了主机地址(例如,主机地址是 sqlxx.123xxx\inst_xyz)。他们还提供了一个 IP 和一个连接数据库的端口,它只在 SQL Server Management Studio 中有效。在 C# 项目的 webconfig 中,如果我使用 IP,那么它会从我的本地开发机器连接。但是部署到hosting后就不行了
同样,如果我在经典 ASP 中使用 sqlxx.123xxx\inst_xyz 作为主机地址,那么它就可以工作。 IP在这里不起作用。 我的问题是,主机 sqlxx.123xxx\inst_xyz 在经典 ASP 中工作,IP 在本地 IIS 中的 ASP.NET C# 中工作,但是 [=42= 的主机是什么] 托管服务器中的 C# ?
请注意,经典ASP项目在主域中,ASP.NETC#项目在主域的子域中。
如果我使用主机(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)**
试试这两个之一:
- 在你的连接字符串前加上一个@:@"sqlxx.123xxx\inst_xy"
- 将连接字符串中的
\
加倍到\
:"sqlxx.123xxx\inst_xy"
我认为反斜杠需要转义。
把这个:
<add key="myCon" value="Server=this_my_host;database=dbname;User Id=myuser;Password=dbpass;"/>
并删除 <connectionStrings>
.
如果您要与远程主机连接,则必须使用 <appSettings>
而不是 <connectionStrings>
字符串。