I have a web service which invokes 2 different web methods.
One of the methods uses a SQL server connection and the other uses DB2.
The ODBC connection can talk to both a DB2 database and SQL server however the SQL has to be designed slightly differently for each method hence the option to switch the connection.
Right now I have a solution in place that is reading a string value from a text file stored on the server.
So if the string is SQL it uses the SQL connection string and ODBC uses the ODBC connection string.
Is there a more efficient way of doing this, without having to read the file in every time a web method is called as I am concerned that in the live environment, there will be bulk loads of data getting sent. So my concern is in the speed and performance of using this method.
Example of how I have implemented this –
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 you just store the value of each in memory after the first file read or just store them in the code.
i.e.
You can read and write these from anywhere and they will persist as long as the server is up (i.e. the app is running in an app domain)
You should also (hopefully) be aware of the security concerns of storing plain text credentials either in code or text docs and (if this is for production) provide some form of encryption / security / reduce user permissions of the account that is being used to access the database 😉