Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
i want when my application install on client and first time run a form open and get value for database connectivity, save this value, after that my project work directly with client database, I use Visual Studio 2013 (Window Form C#) and SQL Server 2012.
Posted

1 solution

Easy! Add a Setting in the VS designer:
1) Open the Solution Explorer pane, and open your project branch.
2) Open the Properties sub-branch, and double click "Settings.settings"
3) In the page that opens, create a new setting value: Name = strConnect, Type = string, Scope = User, Value leave blank.
4) Save and close the settings.
Now, add code:
1) In your main form Constructor, add this code:
C#
string strConnect = Properties.Settings.Default.strConnect;
if (string.IsNullOrWhiteSpace(strConnect))
    {
    frmGetConnectionString f = new frmGetConnectionString();
    if (f.ShowDialog() == DialogResult.OK)
        {
        strConnect = f.ConnectionString;
        Properties.Settings.Default.strConnect = strConnect;
        Properties.Settings.Default.Save();
        }
    else
        {
        Application.Exit();
        }
    }
Now all you have to do is create the form to get the connection string.
 
Share this answer
 
Comments
Member 10028394 6-Aug-15 7:14am    
error on this line (ConnectionString)
strConnect = f.ConnectionString;
OriginalGriff 6-Aug-15 7:25am    
:sigh:
It's your form, not mine - That was just an example property...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900