2010-06-23 168 views
0

我正在開發使用.NET 2.0和Sql Server 2005的Winforms應用程序。我想從SqlServer數據庫所在計算機的其他PC中取回值。使用.NET應用程序通過網絡共享(INTRANET)

,我在App.Config中也做了的AppSettings如下:

<configuration> 
    <appSettings> 
    <add key="DatabasePath" 
    value="Data Source=192.168.1.34,1433;Network Library=DBMSSOCN; 
    Initial Catalog=testingdb;User ID=sa;pwd=pass;"/> 
    </appSettings> 
</configuration> 

但是,我能不能檢索值(名稱&年齡)從服務器到另一臺計算機。 請給我一個解決方案。

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box. 

************** Exception Text ************** 
System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) 
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 
    at System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) 
    at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) 
    at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) 
    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) 
    at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) 
    at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) 
    at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) 
    at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) 
    at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) 
    at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) 
    at System.Data.SqlClient.SqlConnection.Open() 
    at OnlineTest.AdminUser.adminenter() in F:\Online Test - Intranet\OnlineTest\OnlineTest\AdminUser.cs:line 63 
    at OnlineTest.AdminUser.btnok_Click(Object sender, EventArgs e) in F:\Online Test - Intranet\OnlineTest\OnlineTest\AdminUser.cs:line 56 
    at System.Windows.Forms.Control.OnClick(EventArgs e) 
    at System.Windows.Forms.Button.OnClick(EventArgs e) 
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
    at System.Windows.Forms.Button.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 


************** Loaded Assemblies ************** 
mscorlib 
    Assembly Version: 2.0.0.0 
    Win32 Version: 2.0.50727.42 (RTM.050727-4200) 
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll 
---------------------------------------- 
OnlineTest 
    Assembly Version: 1.0.0.0 
    Win32 Version: 1.0.0.0 
    CodeBase: file:///C:/Program%20Files/SystemOrganization/Setup1/OnlineTest.exe 
---------------------------------------- 
System.Windows.Forms 
    Assembly Version: 2.0.0.0 
    Win32 Version: 2.0.50727.42 (RTM.050727-4200) 
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll 
---------------------------------------- 
System 
    Assembly Version: 2.0.0.0 
    Win32 Version: 2.0.50727.42 (RTM.050727-4200) 
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll 
---------------------------------------- 
System.Drawing 
    Assembly Version: 2.0.0.0 
    Win32 Version: 2.0.50727.42 (RTM.050727-4200) 
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll 
---------------------------------------- 
System.Configuration 
    Assembly Version: 2.0.0.0 
    Win32 Version: 2.0.50727.42 (RTM.050727-4200) 
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll 
---------------------------------------- 
System.Xml 
    Assembly Version: 2.0.0.0 
    Win32 Version: 2.0.50727.42 (RTM.050727-4200) 
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll 
---------------------------------------- 
System.Data 
    Assembly Version: 2.0.0.0 
    Win32 Version: 2.0.50727.42 (RTM.050727-4200) 
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll 
---------------------------------------- 
System.Transactions 
    Assembly Version: 2.0.0.0 
    Win32 Version: 2.0.50727.42 (RTM.050727-4200) 
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll 
---------------------------------------- 
System.EnterpriseServices 
    Assembly Version: 2.0.0.0 
    Win32 Version: 2.0.50727.42 (RTM.050727-4200) 
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll 
---------------------------------------- 

************** JIT Debugging ************** 
To enable just-in-time (JIT) debugging, the .config file for this 
application or computer (machine.config) must have the 
jitDebugging value set in the system.windows.forms section. 
The application must also be compiled with debugging 
enabled. 

For example: 

<configuration> 
    <system.windows.forms jitDebugging="true" /> 
</configuration> 

When JIT debugging is enabled, any unhandled exception 
will be sent to the JIT debugger registered on the computer 
rather than be handled by this dialog box. 

回答

1

,SQL服務器不接受連接嘗試:

以下錯誤而檢索顯示。可能是您的連接字符串,請參見http://www.connectionstrings.com/。可能是您的服務器設置。需要更多信息來有效地排除故障。

alt text http://img408.imageshack.us/img408/3558/40512042.png

+0

這是對話框中顯示的錯誤。上面給出的是關於該錯誤的隱藏細節。建立到服務器的連接時發生錯誤。連接到SQL Server 2005時,此故障可能是由於在默認設置下,SQL Server不允許遠程連接。(提供程序:TCP提供程序,錯誤:0 - 連接嘗試失敗,因爲連接方在一段時間後沒有正確響應,或者由於連接的主機未響應而建立的連接失敗 – informative 2010-06-23 06:04:18

+0

是的,就像它說的那樣。選項在數據庫設置中我在我的帖子中放置了一個屏幕截圖,其中的設置是這樣的,但是,這個錯誤可以顯示出來,用於許多不同的連接問題。 – 2010-06-23 06:15:32

+0

我檢查了它。默認情況下,複選框已啓用 – informative 2010-06-23 06:33:20

1

這裏有一些事情你可以嘗試在運行SQL Server的計算機上:

1)Windows防火牆

  • 確保您允許防火牆sqlservr.exe。該可執行文件通常是在$PROGRAMFILES$\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe

  • 允許端口44514331434 Intranet區域

  • 測試您的應用程序。現在,找到並只允許應用程序使用的端口,並阻止其他

2)SQL Server連接

  • 打開了SQL Server Configuration Manager

  • Native Client Configuration部分,啓用Shared MemoryTCP/IPNamed Pipes協議

  • Ri ght之後是SQL Server Network Configuration。確保上述協議已啓用

  • 測試您的應用程序。根據您連接,禁用您不打算使用

此外,如duralai的回答協議的方式,確保SQL服務器設置爲允許遠程連接。這通常是默認情況下,但值得再看一次。

+0

非常感謝。 – informative 2010-06-23 08:58:12