0

I wrote a C# Windows Form application that should communicate with SQL Server database. I have set Connection strings and the program works fine in my system, while other the program fails at connect to the database in other systems.

Since this application will be installed in customer's PC. How can I solve this issue?

The last way I tried was adding ConnectionString to the config file of the project:

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
  </configSections>
<connectionStrings>

  <add name="con"
       connectionString="Data Source=2345pc037\SQLEXPRESS;Initial Catalog=prodDB;Integrated Security=true"
       providerName="System.Data.SqlClient"/>

</connectionStrings>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

And here is the C# code:

SqlConnection cs = new SqlConnection();
           strConn  = string.Format("{0}",ConfigurationManager.ConnectionStrings["con"].ConnectionString);
           cs.ConnectionString = strConn;

Error message stated that either instance name is incorrect or SQL Server does not allow remote connections. Also: "error: 28 - The server does not support the requested protocol."

Thanks in advance for your help!

6
  • Hi, welcome to SO. Please review the guidelines for asking questions. Asking "why isn't this code working?" without the code or any explanatory details is off-topic for SO. We can help you if you add important details. Commented Jan 16, 2015 at 14:59
  • In the configuration manager of SQL enable TCP/IP. Then allow sqlbrowser and sqlserv applications on firewall.(To find the correct path of the .exe files check the configuration manager properties of your instance) Commented Jan 16, 2015 at 15:03
  • 1
    Which issue? What error message are you getting? What is your connection string? Have you specified the correct server address and credentials? Does the server listen to TCP, are the proper ports open on the firewall? Commented Jan 16, 2015 at 15:04
  • Sorry guys that I posted the topic with inappropriate format. Now, it looks better I hope! @theMayer, kevchadders, chridam, Panagiotis Kanavos, Dmitry Bychenko Commented Jan 16, 2015 at 18:12
  • try put port number after sqlexpress separeted by ; Commented Jan 16, 2015 at 20:55

1 Answer 1

1

Here's a couple of things you can check.

1) To check if the server allows remote connections, In SSMS right click on the server, click properties, from the left, click connections, make sure that Allow remove connections to this server is selected.

2) Is the SQL Browser service started? Open Sql Server Configuration Manager and check under services to confirm.

3) If you have a firewall configured on the server, you'll need to configure it to allow connections to the SQL Server (or switch it off temporarily to troubleshoot), or you will receive this error.

4) Can the client PC ping the SQL server. enter ping servername (i.e. ping 2345pc037) in a command window.

5) Confirm that the client can connect to the server. You can do this by entering \severname (i.e. \2345pc037) in a explorer window.

6) In SQL Server Configuration Manager, under SQL Server Network Configuration, ensure that the TCP/IP protocol is enabled and configured to listen on the correct IP address

7) Your connection string indicates that you're using integrated security. Ensure that the user on the client PC has access to the server. - this is not what's causing your problem, but it might once you can get connected.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much @Spock for your comprehensive comment. But I wonder if a client is sitting in a stand-alone system. I mean how can I make this to work with the database file attached to the application in a computer outside the network.
All of these points apply to a network installation of sql server
Indeed! thanks so much! But don't you mean that this connection string cannot be used for a stand-alone system?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.