views:

37

answers:

2

I am developing a winforms application using .NET 2.0 and Sql Server 2005. I want to just retieve the values from another PC from the Computer in which SqlServer Database is present.

The appsettings that I have done in App.Config is as follows:

    <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>

But, I can't able to retrieve values (Name & Age) from Server to another Computer. Please, give me a solution.

The following error is shown while retrieving:

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  A: 

Your SQL server is not accepting the connection attempt. Could be your connection string, see http://www.connectionstrings.com/. Could be your server setup. Need more info to troubleshoot effectively.

alt text

Dustin Laine
This is the Shown Error in the Dialog Box. Above that I had given is hidden details about that error. An error has occured 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 theconnected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
informative
Yes, just like it says. That is an option in the database settings. I placed a screen shot in my post where the setting is. However, that error can be shown for many different connectivity problems.
Dustin Laine
I checked it. By default the checkbox is enabled.
informative
Now, i disable windows firewall from the Server PC. Now it shows the following error. Login failed for user ''. The user is not associated with a trusted SQL Server connection.
informative
Then you have some other network connectivity issue. Can you ping that server? Can you telnet to port 1433? Let me know if you can do any of those.
Dustin Laine
I think that I am having problem with that appsettings configuration. Please check that and inform me if any other attribute to be added for the trusted connection.
informative
Is the SQL Server on the same box that your app is on? Here is basic trusted config connection string `Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;` Also not sure why you are using APPSetting, when you should use connectionStrings element http://msdn.microsoft.com/en-us/library/ms254494%28VS.80%29.aspx
Dustin Laine
Finally it works fine. Very much thanks for all your suggestions. I make the Sql Server Agent to run and enabled everything in Protocols in SQLEXPRESS and PROTOCOLS for MSSQLSERVER and also enabled everything in Client Protocols under Sql Native Client Configuration. Also, I have not included integrated security and trusted connection in appsettings. Thanks, Once again for giving nice suggestions.
informative
A: 

Here are a few things you can try on the machine that is running SQL Server:

1) Windows Firewall

  • Ensure you allow sqlservr.exe in the Firewall. This executable is usually at $PROGRAMFILES$\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe

  • Allow ports 445, 1433 and 1434 in the Intranet zone

  • Test your application. Now find and allow only the ports that your app uses, and block the rest

2) SQL Server Connectivity

  • Open up SQL Server Configuration Manager

  • In the Native Client Configuration section, enable Shared Memory, TCP/IP and Named Pipes protocols

  • Right after that is SQL Server Network Configuration. Make sure the above protocols are enabled there

  • Test your application. Depending on the way you connect, disable the protocols that you do not intend to use

Also, as in duralai's answer, ensure that SQL Server is set to allowing remote connections. This is usually on by default but worth another look.

Druid
Thanks very much.
informative