简体   繁体   English

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

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: 尝试以下两种方法之一:

  1. Put a @ in front of your connection string: @"sqlxx.123xxx\\inst_xy" 在连接字符串前放置一个@:@“ sqlxx.123xxx \\ inst_xy”
  2. Double the \\ 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.

相关问题 asp.net,c#和sql server之间的连接(两个版本均为2012) - connection between asp.net , c# and sql server ( both versions are 2012) SQL Server数据库连接C#ASP.NET - SQL Server Database Connection C# ASP.NET C#ASP.NET for SQL的连接字符串 - Connection string for C# ASP.NET for SQL asp.net项目C#,SQL Server,插入不起作用 - asp.net project C#, SQL server, Insert is not working ASP.NET和SQL Server连接字符串 - ASP.NET & SQL Server connection string ASP.NET MVC C#Razor SQL 1 of 2几乎相同的更新查询不起作用 - ASP.NET MVC C# Razor SQL 1 of 2 almost identical Update Queries doesn't work 使用asp.net C#将SQL Server 2016中的一个数据库复制到SQL Server 2012中的另一个数据库 - Copy one database in SQL Server 2016 to another in SQL Server 2012 using asp.net C# 从数据库SQL Server 2012 asp.net C#填充Datalist ItemTemplate内的CheckBoxList - Populate CheckBoxList inside Datalist ItemTemplate from database SQL Server 2012 asp.net C# 如何调试包含ASP经典,ASP.NET,C#和VB的项目? - How to Debug a project that includes ASP classic, ASP.NET , C# and VB? OUTPUT INSERTED Id / SCOPE_IDENTITY()在C#(ASP.NET Core Razor Pages)SQL查询中返回null,在SQL Server Management Studio中正常工作 - OUTPUT INSERTED Id/SCOPE_IDENTITY() returns null in C# (ASP.NET Core Razor Pages) SQL query, works fine in SQL Server Management Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM