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

dario
  • 5,149
  • 12
  • 28
  • 32
AlanD
  • 55
  • 1
  • 8
  • why not check out this site it's very useful [C# Connectiong Strings to Databases](http://www.connectionstrings.com) also your `strConn = ` that string.Format({0}"` is incorrect it should be `strConn = string.format("{0}", ConfigurationManager.ConnectionStrings["con"].ConnectionString);` `connectionString="Data Source=2345pc037\SQLEXPRESS;` is the problem as well – MethodMan Jan 16 '15 at 19:37
  • 1
    Have a look at [this](http://stackoverflow.com/questions/13238219/sql-server-express-cannot-connect-error-28-server-doesnt-support-requested-p). It's not a connection string problem. – dario Jan 16 '15 at 19:38

1 Answers1

0

This should fix your problem

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

If the username and pass word are required then do the following here is a template.

  <connectionStrings>
    <add name="CMSConnectionString" connectionString="Data Source=yourDataSource;Initial Catalog=YourCatalog;User Id=Your UserId;Password=Your Password;" />
  </connectionStrings>
MethodMan
  • 18,625
  • 6
  • 34
  • 52