問題描述
首先:您在這篇文章中讀到的所有內容僅在安裝了 Windows 10 April 2018 更新的情況下發生.安裝前和更新卸載后都沒有問題.
First of all: everything you will read in this post happens only if Windows 10 April 2018 update is installed. No problem before installation and after update uninstallation.
安裝 Windows 10 1803 更新后,我所有從網絡映射驅動器或 UNC 路徑運行的 VB 程序(VB6、.NET 和 WPF)都無法連接到 SQL 服務器,如果在本地放置并執行相同的可執行文件,則沒問題驅動器(在同一網絡中的 2 臺電腦上測試):
After installing Windows 10 1803 update, all my VB program (VB6, .NET and WPF) running from network mapped drive or UNC path can't connect to SQL server, no problem if the same executable is placed and executed from local drive (tested on 2 pc in the same network):
- 遠程 SQL 服務器,本地驅動器上的 exe:OK
- 相同遠程 SQL 服務器,映射網絡驅動器上的 相同 exe(具有完全讀/寫訪問權限):錯誤
- Remote SQL server, exe on local drive: OK
- Same remote SQL server, same exe on mapped network drive (with full read/write access): ERROR
這是錯誤(可能對解決此問題沒有意義):
This is the error (maybe not significat to solve this problem):
與 SQL Server 建立連接時發生與網絡相關或特定于實例的錯誤.服務器未找到或無法訪問.驗證實例名稱是否正確以及 SQL Server 是否配置為允許遠程連接.(提供程序:SQL 網絡接口,錯誤:26 - 錯誤定位服務器/指定的實例).
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).
簡單的VB.NET代碼復現問題(將代碼放在一個簡單的形式,在button_click事件中加一個按鈕,設置值連接到SQL服務器,編譯,將exe文件保存在網絡路徑上并執行)):
Simple VB.NET code to reproduce the problem (place the code in a simple form with a button in the button_click event, set values to connect to the SQL server, compile, save the exe file on a network path and execute it):
Dim myConnectionString As String
Dim mySqlConnectionStringBuilder As New SqlConnectionStringBuilder()
mySqlConnectionStringBuilder.DataSource = myServer
mySqlConnectionStringBuilder.InitialCatalog = myDatabase
mySqlConnectionStringBuilder.UserID = myUtente
mySqlConnectionStringBuilder.Password = myPassword
myConnectionString = mySqlConnectionStringBuilder.ConnectionString
Dim mySqlConnection As New SqlConnection(myConnectionString)
mySqlConnection.Open() <- error
異常:
System.Data.SqlClient.SqlException (0x80131904): Si è verificato un errore di rete o specifico dell'istanza mentre si cercava di stabilire una connessione con SQL Server. Il server non è stato trovato o non è accessibile. Verificare che il nome dell'istanza sia corretto e che SQL Server sia configurato in modo da consentire connessioni remote. (provider: SQL Network Interfaces, error: 26 - Errore nell'individuazione del server/dell'istanza specificata)
in System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
in System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
in System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
in System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
in System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
in System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
in System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
in System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
in System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
in System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
in System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
in System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
in System.Data.SqlClient.SqlConnection.Open()
in RiepilogoOreTimer.RiepilogoOreTimerWindow.ConnessioneOK()
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:-1,State:0,Class:20
有什么想法嗎?
更新:如果我卸載 2018 年 4 月的更新,問題就會消失,即使在網絡驅動器上執行該程序也能正常工作,但這不能成為解決方案...
Update: If I uninstall the April 2018 update the issue go away and the program works fine even if executed on a network drive, but this can't be the solution...
2018 年 8 月 5 日更新:我注意到 2018 年 4 月的更新帶來了一些 安全變化:
Update 08/05/2018: I noticed that April 2018 update brought some changes in security:
Windows 10 版本 1803 提供額外保護:
Windows 10, version 1803 provides additional protections:
- 新的攻擊面減少規則
- 受控文件夾訪問現在可以阻止磁盤扇區
這可能是問題的原因嗎?我不是安全經理,所以我不能說這是否會導致我的問題
Could it be the cause of the issue? I'm not a security manager so I can't say if this can cause my problem
2018 年 9 月 5 日更新:我在 this 帖子:
Windows 10 更新 1803 無法打開網絡連接SMBv1 共享上的可執行文件(如 Windows Server 2003)
Windows 10 update 1803 does not open network connections on executables files on SMBv1 share (as Windows Server 2003)
但我不知道什么是 SMBv1...有人可以幫助我嗎?
but I don't know what SMBv1 is... somebody can help me?
推薦答案
終于發現問題了:在共享文件夾的服務器中,SMBv2被禁用(不知道為什么)所以只有SMBv1處于活動狀態;從同一網絡中的同一客戶端執行的同一程序但位于啟用了 SMBv2 的服務器上運行正常.
Finally I found the problem: in the server with the shared folder, SMBv2 is disabled (I don't know why) so only SMBv1 is active; the same program executed from the same client in the same network but located on a server with SMBv2 enabled works fine.
所以問題是關于 SMBv1 共享,從 Windows 10 1803 開始??棄用
So the problem is about SMBv1 share, deprecated starting from Windows 10 1803
這篇關于如果從網絡路徑執行 EXE,則 SqlConnection 錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!