Databases Reference
In-Depth Information
ConnectionString Property
The ConnectionString property allows you to set the connection string through code. The property
uses a private variable to store the current connection string, which is used to provide the information
needed to connect to the data source. Most developers are familiar with this property because of its
frequent use in both traditional ADO and ADO.NET. The ConnectionString property is used to
indicate the file that you are going to parse. The user of your data processing extension should input the
path to the file they wish to parse into the connection string. You are storing the connection string in the
private member variable m_connString .
C#
public string ConnectionString
{
Get {return m_connectionString;}
Set {m_connectionString = value;}
}
VB.NET
Public Property ConnectionString() As String _
Implements IDbConnection.ConnectionString
Get
Return m_connString
End Get
Set(ByVal Value As String)
m_connString = Value
End Set
End Property
You want to enforce that the value passed into the ConnectionString property meets your criteria for
supplying the information needed to connect to the data source. You want to enforce that the string is in
the format:
FileName=c:\FileName.xml
You will accomplish this through the use of regular expressions. You need to modify the Set accessor to
reflect this change. First, you are going to execute that static/shared Match method of the Regex class.
You are passing in an expression that basically says “Parse the connection string and make matches on
character arrays that are preceded by FileName= and are not composed of beginning of line characters
or semicolons.” All that is left is test to see if the filename is valid, and, if so, assign it to your private file-
name variable. Your code should resemble that below.
C#
set
{
this.m_connectionString = value;
Match m = Regex.Match (value, “FileName=([^;]+)”, RegexOptions.IgnoreCase);
if (!m.Success)
{
throw (new ArgumentException (“'FileName=<filename>' must be present in the
connection string and point to a valid DataSet xml file”, “ConnectionString”));
}
Search WWH ::




Custom Search