WPF application database connect with remote database -
i creating wpf application , there 2 databases, 1 on client computer , other 1 on remote server. , client asks me sync these 2 databases. asked me when wpf application connects internet, should sync local data remote server, , if not connected internet, should save data locally.
tell me there way connect local , remote server, can wpf access 2 different databases on 2 different computers via internet
this boils down using 2 different connection strings need them (either via ado or ef or you're accessing data).
void dostuff() { using (sqlconnection conn = new sqlconnection("your first connection string here")) using (sqlcommand cmd = new sqlcommand) { cmd.connection = conn; // stuff command } using (sqlconnection conn = new sqlconnection("your second connection string here")) using (sqlcommand cmd = new sqlcommand) { cmd.connection = conn; // stuff command } }
to access remote database, need correct credentials, connection string, , remote db must allow incoming connections. client should have details.
for more configuration-based approach, might this:
<connectionstrings> <add name="localconnection" connectionstring="your first connection string here" /> <add name="remoteconnection" connectionstring="your second connection string here" /> </connectionstrings>
and use so:
string connstr = system.configuration.configurationmanager.connectionstrings["localconnection"].connectionstring;
or wire entity framework/orm classess accordingly.
Comments
Post a Comment