Monday, 15 March 2010

c# - Alternative to setting database connection from file -



c# - Alternative to setting database connection from file -

i have web service invokes 2 different web methods.

one of methods uses sql server connection , other uses db2.

the odbc connection can talk both db2 database , sql server sql has designed differently each method hence alternative switch connection.

right have solution in place reading string value text file stored on server.

so if string sql uses sql connection string , odbc uses odbc connection string.

is there more efficient way of doing this, without having read file in every time web method called concerned in live environment, there mass loads of info getting sent. concern in speed , performance of using method.

example of how have implemented -

string dbconsql = "sql-connection-string"; string dbconodbc = "odbc-connection-string"; string connection = system.io.file.readalltext(@"filepath"); [webmethod] public string stringreturn(string connection) { if(connection == "sql") { string con = "dbconsql"; string sql = "sql" } if(connection == "odbc") { con = dbconodbc; sql = "odbc sql"; } //do stuff here }

why don't store value of each in memory after first file read or store them in code.

i.e.

static class globals { public static string db2connstr = string.empty; public static string mssqlstr = string.empty; }

you can read , write these anywhere , persist long server (i.e. app running in app domain)

you should (hopefully) aware of security concerns of storing plain text credentials either in code or text docs , (if production) provide form of encryption / security / cut down user permissions of business relationship beingness used access database ;)

c# web-services connection-string

No comments:

Post a Comment