Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem With ConnectionStringBuilder
Message
From
02/02/2010 15:01:23
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
01447146
Message ID:
01447162
Views:
35
>In my DataAccess class I have a private method called GetConnectionString to generate the connection string based on property values. I'm trying to use it to connect to an Access database. In this method is a switch which is evaluated based on the InvariantName. For the OleDb option I have:
>
>
>
>DbConnectionStringBuilder csb = _Factory.CreateConnectionStringBuilder();
>
>.
>.
>.
>
>case "System.Data.OleDb":
>    if (_Provider != "")
>    {
>        csb.Add("Provider", _Provider);
>    }
>    if (_DataSource != "")
>    {
>        csb.Add("Data Source", _DataSource);
>    }
>    if (_InitialCatalog != "")
>    {
>        csb.Add("Initial Catalog", _InitialCatalog);
>    }
>    if (_TrustedConnection)
>    {
>        csb.Add("Integrated Security", "SSPI");
>    }
>    else
>    {
>        if (_UserName != "")
>        {
>            csb.Add("User Id", _UserName);
>        }
>
>        if (_Password != "")
>        {
>            csb.Add("pwd", _Password);
>        }
>    }
>
>    break;
>
>
>
>Then outside the switch I have:
>
>
>return csb.ConnectionString;
>
>
>When I step to this line and hover over 'csb', I see
>
Provider=Microsoft.Jet.OLEDB.4.0;Data Source="M:\APEX Master Database.mdb";Integrated Security=SSPI
>
>When I hover over 'ConnectionString' I see:
>
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"M:\\APEX Master Database.mdb\";Integrated Security=SSPI
>
>Notice the extra slashes before and after the database name.

You may want to include an @ sign in front of your string values in the properties where you have that assigned. In other words like this.
///
/// DataSource Property
///
public string DataSource
{
     get { return _dataSource; }
}
private string _dataSource = @"M:\APEX Master Database.mdb...";
Like Viv said about the escape characters, the @ sign will negate that.
Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform