c# - Transform odbc connection strings to SqlClient -


we've got various apps connect sql server, using odbc, , others via sqlclient, therefore leading strings in both formats (!).

i'm trying consolidate strings, there standard way can store them in odbc , transform them sqlclient apps need them?

ok i've created (currently) quick , dirty function below uses connectionstringbuilder, i'm sure there must more elegant way of doing this... (?) seems smelly.

    /// <summary>     /// returns sqlclient connection string odbc string      /// </summary>     private string odbctosqlclient(string odbcconnectionstring)     {                    odbcconnectionstringbuilder builder = new odbcconnectionstringbuilder(odbcconnectionstring);                                 if (builder.containskey("uid"))                     {             //standard connection             return string.format("server={0};database={1};user id={2};password={3};", builder["server"], builder["database"], builder["uid"], builder["pwd"]);         }         else          {             //trusted connection             return string.format("server={0};database={1};trusted_connection=true;", builder["server"], builder["database"]);                         }     } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -