c# - setup and deployment with database -


i want create exe of c# windows application project. created exe. problem don't know how include database exe. because taking backup of database , restore backup system in want install exe. database created in sql server2012. in c# code connection string set system server name. if want install in system, need change connection string server name of system in want install exe. not possible in time. there method done these without changing in code? created exe using install shield. thanks.

normally database settings should configurable i.e. user sets settings through application ui written configuration file. if give settings through configuration file hardcoding, exe need not built everytime.

for getting existing database, application should coded create blank database if database in server doesn't exist. existing data can imported through administrator mode od application or manually done in sql server.

the following code shows how can store connection strings in app.config file.

<?xml version="1.0" encoding="utf-8" ?> <configuration>    <connectionstrings>       <add name="mydbconnectionstring" providername="system.data.sqlclient"             connectionstring="data source=localhost;initial catalog=mysqlserverdb; integrated security=true" />    </connectionstrings> </configuration> 

once have saved connection string in app.config file can use system.configuration.configurationmanager class read connection string in code.

connectionstringsettings  consettings = configurationmanager.connectionstrings["mydbconnectionstring"]; 

connectionstringssettings class provides properties read connection string settings in program following code shows.

string name = consettings.name;  string providername = consettings.providername; string connectionstring = consettings.connectionstring; 

the above code has been taken link

for detailed example check article on codeproject


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -