我有一个数据库,我知道我可以连接的事实。我用过odbc - >我得到了系统DSN - >我输入了所有凭据,它可以测试连接正常,但每当我尝试在Visual Studio中的数据连接中刷新数据库时,它表示服务器资源管理器无法执行此操作。建立与SQL Server的连接时发生与网络相关或特定于实例的错误。我已经检查了连接字符串中的用户名和密码,这一切都是正确的。还有什么可以做的尝试和我可能忘记的视觉工作室联系。 web.config中的字符串是:
<add name="DefaultConnection" connectionString="Data Source=*********;
Initial Catalog=*******Dev;Persist Security Info=True;User
ID=********;Password=**********" providerName="System.Data.SqlClient" />
我也试图禁用我的防火墙
当我运行代码时,它不会打开该用户建议的内容。在代码: cnn.Open(); 它会崩溃。它给出的信息是:
>Can not open connection ! System.Data.SqlClent.SqlException (Ox80131904): 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) System.ComponentModel.Wn32Exception (Ox80004005): The netvvork path was not
found
at System. Data.SqlClent.SqIInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action' 1 wrapCloseInAction)
at System. Data.SqlC5ent.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClent.TdsParser.Connect(ServerInfo serverlnfo, SqIInternalConnectionTds connHandler, Boolean ignoreSniOpenTlmeout, Int64 timerExpire, Boolean
encrypt, Boolean trustServerCert, Boolean integratedsecurity, Boolean wthFailover)
at System.Data.SqlClent.SqIInternalConnectionTds.AttemptOneLogin(ServerInfo serverlnfo, String newPassword, Securestring newSecurePassword, Boolean
ignoreSniOpenTlmeout, TimeoutTlmer timeout, Boolean wthFailover)
at System.Data.SqlClent.SqIInternalConnectionTds.LoginNoFailover(ServerInfo serverlnfo, String newPassword, Securestring newSecurePassword, Boolean
redirecteduserlnstance, SqlConnectionString connectionoptions, SqlCredential credential, TimeoutTlmer timeout)
at System. Data.SqlClent.SqIInternalConnectionTds.OpenLoginEnfist(TlmeoutTlmer timeout, SqlConnectionString connectionoptions, SqlCredential credential, String
newPassword, Securestring newSecurePassword, Boolean redirecteduserlnstance)
at System. Data.SqlClent.SqIInternalConnectionTds..ctor(DbConnectionPooIIdentity identity, SqlConnectionString connectionoptions, SqlCredential credential, Object
providerlnfo, String newPassword, Securestring newSecurePassword, Boolean redirecteduserlnstance, SqlConnectionString userConnectionOptions, SessionData
reconnectSessionData)
at System. Data.SqlClent.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object pooGroupProviderInfo,
DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions useroptions)
at System.Data.Provider3ase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningobject, DbConnectionOptions options,
DbConnectionPoolKey poolKey, DbConnectionOptions useroptions)
at System.Data.Provider3ase.DbConnectionPool.CreateObject(DbConnection owningobject, DbConnectionOptions useroptions, Dbconnectionlnternal oldConnection)
at System.Data.Provider3ase.DbConnectionPool.UserCreateRequest(DbConnection owningobject, DbConnectionOptions useroptions, Dbconnectionlnternal
oldConnection)
at System.Data.Provider3ase.DbConnectionPool.TryGetConnection(DbConnection owningobject, Ulnt32 waitForMuttipleObjectsTmeout, Boolean allowCreate, Boolean
ontyOneCheckConnection, DbConnectionOptions useroptions, Dbconnectionlnternal& connection)
at System.Data.Provider3ase.DbConnectionPool.TryGetConnection(DbConnection owningobject, Taskcompletionsource' 1 retry, DbConnectionOptions useroptions,
Dbconnectionlnternal& connection)
at System.Data.Provider3ase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, Taskcompletionsource' 1 retry, DbConnectionOptions
useroptions, Dbconnectionlnternal oldConnection, Dbconnectionlnternal& connection)
at System. Data. Provider3ase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory,
Taskcompletionsource' 1 retry, DbConnectionOptions useroptions)
at System. Data. Provider3ase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory,
Taskcompletionsource' 1 retry, DbConnectionOptions useroptions)
at System. Data.SqlC5ent.SqlConnection.TryOpenInner(TaskCompletionSource' 1 retry)
at System. Data.SqC5ent.SqlConnection.TryOpen(TaskCompletionSource' 1 retry)
at System. Data.SqlClent.SqlConnection.Open()
ClientConnectionId:00000000-0000-0000-00000000000
答案 0 :(得分:0)
尝试..像这样。并找到错误,它说的是什么?
string connetionString = null;
SqlConnection cnn ;
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
cnn = new SqlConnection(connetionString);
try
{
cnn.Open();
MessageBox.Show ("Connection Open ! ");
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! ");
}
答案 1 :(得分:0)
我确实使用过UDL并且有效。 I&#39; M痛心地说,但答案很简单。我必须做的是:
Data Source = Server_Name.com
而不是Server_Name。它是一个真正的数据库,所以我试图保护它,但那就是问题所在!非常感谢你告诉我这个名字有问题,这是帮助我弄明白的原因。 谢谢用户/尼克帮助我缩小问题范围