I am trying to make my application database agnostic and in doing so I have elected to use the DBConnection Class instead of the SqlConnection, OracleConnection, etc that currently litter my application. So I am having an issue with the DBConnectionStringBulder adding double quotes in my connection string. When I use the OdbcConnectionStringBuilder the extra double quotes are omitted. So now I need to replace the double quotes after my connection string is built to avoid any issues.
OdbcConnectionStringBulder Connection String:
Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=C:\Temp\;Extensions=asc,csv,tab,txt;Persist Security Info=False
DbConnectionStringBulder Connection String:
Driver="{Microsoft Text Driver (*.txt; *.csv)}";Dbq=C:\Temp\;Extensions=asc,csv,tab,txt;Persist Security Info=False
So I am guessing that this is a bug in the DbConnectionStringBuilder but I wanted to see if I was doing something wrong or not. Here is the applicable code with my workaround:
OdbcConnectionStringBuilder odbcConnectionString = new OdbcConnectionStringBuilder();
odbcConnectionString.Add("Driver", "{Microsoft Text Driver (*.txt; *.csv)}");
odbcConnectionString.Add("Dbq", @"C:\Temp\");
odbcConnectionString.Add("Extensions", "asc,csv,tab,txt");
odbcConnectionString.Add("Persist Security Info", "False");
Console.WriteLine(odbcConnectionString.ConnectionString);
DbConnectionStringBuilder dbConnectionString = new DbConnectionStringBuilder();
dbConnectionString.Add("Driver", "{Microsoft Text Driver (*.txt; *.csv)}");
dbConnectionString.Add("Dbq", @"C:\Temp\");
dbConnectionString.Add("Extensions", "asc,csv,tab,txt");
dbConnectionString.Add("Persist Security Info", "False");
Console.WriteLine(dbConnectionString.ConnectionString.Replace("\"", string.Empty)); //<-- My Workaround.
Here is a link to .Net Fiddle: https://dotnetfiddle.net/3qhB5S