Databases Reference
In-Depth Information
Figure 10-3. Displaying connection information
How It Works
The ConnectionString property can be both read and written. Here you just display it.
Console.WriteLine(
"\tConnection String: {0}",
conn.ConnectionString);
You can see the value you assign to it, including the whitespace, in the verbatim
string.
What's the point? Well, it's handy when debugging connections to verify that the
connection string really contains the values you thought you assigned. For example, if
you're trying out different connection options, you may have different connection string
parameters in the program. You may have commented out one, intending to use it later,
but forgot about it. Displaying the ConnectionString property helps to see whether a
parameter is missing.
The next statement displays the Database property. Since each SQL Server instance
has several databases, this property shows which one you're initially using when you
connect.
Console.WriteLine(
"\tDatabase: {0}",
conn.Database);
In this program, it displays
Database: master
Search WWH ::




Custom Search