的Visual Studio连接到数据库,但使用内相同的连接字符串应用程序不能
使用SSMS和Visual Studio 2015年的Server Explorer
Data Connections
标签下,我可以执行查询在远程服务器KOSH没有问题。为什么在Visual Studio/IIS Express中本地运行的MVC应用程序无法做到这一点?的Visual Studio连接到数据库,但使用内相同的连接字符串应用程序不能
使用VS2015的连接Properties
,我得到它的连接字符串:
Data Source=123.456.78.9;Persist Security Info=True;User ID=Foo;Password=Bar
使用该连接字符串,MVC应用招呼以:
"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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
内部异常消息:
"The network path was not found"
我知道服务器/防火墙/网络设置是正确的。这留下了应用程序。
using(var connection = Database.Connection(conInfo.ConnectionString, provider)) {
// rowCountSql: SELECT SUM(rows) TM_ROWCOUNT FROM sys.partitions
// WHERE object_id = object_id(@tableName) and index_id IN (0,1)
// Any other SQL yields same error
var countTask = connection.QueryAsync(rowCountSql, new { tableName = Editor.TableName });
}
使用异步,因为Oracle版本的查询可能需要几秒钟才能返回。 应用程序应该是正确的,因为它从家中(也是服务器的位置)连接到同一台服务器,并且在运行2008R2到2014的远程数据中心中的相同数据库中没有问题。
Database.Connection()
是:
// This is unlikely to be the problem as it is very well tested
public static DbConnection Connection(string connectionString, string databaseProvider) {
DbProviderFactory databaseFactory = DbProviderFactories.GetFactory(databaseProvider);
DbConnection connection = databaseFactory.CreateConnection();
if(connection != null)
connection.ConnectionString = connectionString;
return connection;
}
我敢打赌,我失去了一些东西简单,但我会很感激的帮助是什么,可能是。
正如我在评论说,可以将一块代码的:
conInfo.ConnectionString
不包含要正确的连接字符串。
检查出来
你确定你的conInfo.ConnectionString是正确的吗? – Henrique
您的Oracle DB没有名称吗?使用IP地址通常是高级选项。 – silkfire
@Henrique:我有很多奇妙的原因可以肯定'conInfo.ConnectionString'包含我一直在编辑的字符串,所有这些都显然是错误的,因为这是问题所在。 (脸蛋)。 谢谢。如果您发布的是完整回复,我会将其标记为正确,因为“无论如何检查明显的”往往是解决方案。 –