Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
am updating local machine database by using connection method in .net..
now i want to update server side database(same table in local machine) by using same program..
i know the server database username,database name,password,table name ..
please anyone help me regarding this....how should i follow in connection .......
Posted

First set connectionstring in web.config/app.config

Then read connectionstring from there
sqlconnection con=new sqlconnection(connectionstring from config)
 
Share this answer
 
Comments
Kumar Kovuru 22-Nov-13 3:56am    
How should i follow in web.config?
Hi Kumar,

If you have more than one region for development(DEV,UAT,PROD) its a good practise to store connection string in web.config.
Which will be easier for you to read the connection string and establish the connection in code behind file.

In Web.config file find connnectionstring section and replace with below code

XML
<connectionStrings>
<add name="localConnectionString" connectionString="SERVER=.\SQL2008;DataBase=StudentDatabase;UID=rk.prabakar;pwd=*****;" providerName="System.Data.SqlClient"/>
<add name="serverConnectionString" connectionString="Server=server\SQL2008;Database=StudentServerDatabase;User ID=sa;Password=*******;providerName="System.Data.SqlClient"/>
</connectionStrings>


In server side code,
C#
con = new SqlConnection(ConfigurationManager.ConnectionStrings["localConnectionString"].ToString()); //Points to local database connection string
or
con = new SqlConnection(ConfigurationManager.ConnectionStrings["serverConnectionString"].ToString()); //Points to server database connection string

Once you finalized with database, you can establish the connection like con.open();

And you start executing your command.
So connecting to server database is solely depends on the connection string.

Regards,
RK
 
Share this answer
 
v2

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