0

I want to publish a desktop application in another host computer. I tried publishing with SQL Server Compact but it didn't work. What changes should I make in Visual Studio and SQL Server so I can install my application in any computer?

What changes should I make to the connection information shown here?

private void FrmLogin_Load(object sender, EventArgs e)
{
    GlobalConnection.strServer = "myserver\\SQLEXPRESS";
    GlobalConnection.strPWD = "123456";
    GlobalConnection.strDatabase = "NUS";
    GlobalConnection.strUID = "sa";
    GlobalConnection.SetupConnection();
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    And what is not working when you deployed the application? – rene Apr 14 '14 at 13:19
  • The system gets installed in another computer but it shows database error. It works fine in my own computer where I developed it. – user3382196 Apr 14 '14 at 13:21
  • What is the EXACT error you get? – rene Apr 14 '14 at 13:22
  • "....The server was not found or not accessible...." – user3382196 Apr 14 '14 at 13:27
  • 1
    @user3382196 just try to keep connection string in configuration file. You can deal with multiple connection as well. Hope posted answer is helpful. – Hassan Apr 14 '14 at 13:31
  • See if [this](http://stackoverflow.com/questions/20300623/error-the-server-was-not-found-or-was-not-accessible-when-trying-to-connect) helps. – rene Apr 14 '14 at 13:31
  • If you are sure that you have created a database named `NUS`, with user access name `sa` and password `123456` then try to change the `strServer` to `GlobalConnection.strServer = ".\SQLEXPRESS";` the `myserver` is probably the name of the PC that SQL is installed. – rosko Apr 14 '14 at 13:56
  • Yes, the database is created in my computer and it is working well in my computer. But, when I deploy and install the application in another computer, the applications shows an database error. – user3382196 Apr 14 '14 at 14:00
  • 1
    Let me try one last time: is **myserver** the name of the computer that runs sqlexpress? On the computer where you install the application if you open a command prompt and do `ping myserver` does it respond? On **myserver** is sqlexpress configured to listen on one of its networkaddresses? (see the link in my earlier comment how to check/configure that) . – rene Apr 14 '14 at 14:09
  • @rene yes, it does respond. I did go through the link and the errors are the same but I didn't get the solution. – user3382196 Apr 14 '14 at 14:16
  • Side note: **DO NOT** use the `sa` account - ***NOT EVER!*** , not even in development or testing! Use appropriate accounts , but not `sa` ! – marc_s Apr 14 '14 at 14:31
  • Thanks for the info @marc_s. Can you tell me if there is any difference in Windows Authentication and SQL Server authentication? – user3382196 Apr 14 '14 at 14:34

2 Answers2

0

If SQL Server Express is installed on the target computer, you have enabled the "sa" account (it should be disabled by default) and set the password "123456" to the "sa" account, and the SQL Server Express instance name is SQLEXPRESS, you can modify your connection information to target the local computer (regardless of its name).

GlobalConnection.strServer = ".\\SQLEXPRESS";

If you are looking at how to automatically deploy and setup the target machine, there are quite a few ways, so I outline a generic method here:

  • Installer that can automate the installation and configuration of SQL Server Express (typically with a different app specific user account, not the "sa" one).
  • Install your desktop application and create a shortcut to it,
  • Config information should be targeting the local machine through use of the ., then the SQL Server instance name from the automation in the first step and using either Windows Auth or the custom user account/pwd that was also auto-created.

This is a pretty generic overview I have provided, but hopefully helps point you in the right direction.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
justinlabenne
  • 793
  • 3
  • 6
-2

Configure the connection string of your database in the file App.Config in the project by adding the following elements to app.config

<configuration>
    <appSettings>  
        <add name="somename" 
             providerName="System.Data.sqlclient" 
             connectionString="your connection string" />
    </appsettings>
</configuration>

and get your connection string using

 constr = ConfigurationManager.ConnectionStrings["somename"].ConnectionString;
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Sorry, but I am unsure where should I insert constr = ConfigurationManager.ConnectionStrings["somename"].ConnectionString; – user3382196 Apr 14 '14 at 13:38
  • Should I replace it with the code given above?? Please reply – user3382196 Apr 14 '14 at 13:47
  • 1
    No @user3382196 you cannot simply do that. Just look into details of adding config file in your application and manage your connections in configuration file. – Hassan Apr 14 '14 at 13:50
  • 1
    That's **NOT** going to work! If you want to use `ConfigurationManager.ConnectionStrings[...]`, then you need to add your connection string info to the `` section (**NOT** the ``!!) in your config file – marc_s Apr 14 '14 at 14:17