我有一个C#程序连接到SQL Server。它工作正常,在测试计算机与SQL Server 2012的,但是对生产环境与2008年在生产环境中无法正常工作,它会报告异常,因为这样,无法连接到SQL Server,但Excel和ODBC配置可以
Unhandled Exception: System.Data.SqlClient.SqlException: A network-related or in stance-specific error occurred while establishing a connection to SQL Server. Th e server was not found or was not accessible. Verify that the instance name is c orrect and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) -- -> System.ComponentModel.Win32Exception: Access is denied
这里是我的连接代码,
connStrSql = "Server=" + sqlserver + "; Database=" + sqldb + "; Trusted_Connection=True";
SqlConnection sqlConn = new SqlConnection(connStrSql)
sqlConn.Open();
目标平台是x86,目标框架是4.5。有趣的是,Excel和ODBC配置可以连接到数据库而不抱怨。 C#程序是否使用连接到SQL Server的不同方式?我该如何解决这个问题?
你连接尝试连接到SQL Server远程? –
是的,我应该尝试不同的网络库,如tcp而不是默认的命名管道? – tabasco
好的。 Excel是远程的还是本地的SQL Server? –