Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Creating connection string information requires that you create an object that is derived from the IConnectionString class, such as DB2OdbcConnectionString or DB2OleDbConnectionString. After you create the string, you can save, modify, or retrieve information from it by using the associated properties.
Retrieve and modify connection string information
Create a new connection string by calling the specific type of connection string constructor, using the file path of the .udl file that contains the specified connection string.
Or, you can call
ReadUDLfor the specifiedConnectionStringtype. Many of theConnectionStringclasses also have aClonemethod that you may want to use. Note thatClonedoes not load the current instance into active memory, but instead makes a copy that you can later modify and save to disk.If you are attempting to retrieve data from a connection string that you currently have an instance of, you can call
Load. For example, if you recently created a new connection string and calledSave, you can retrieve the object from storage and into active memory by callingLoadon the object again.If you use a path that describes a file that does not exist, the system creates a .udl new file using the path described.
Retrieve the connection data from your current instance by using
GetStringor by accessing the relevant property.Using
GetStringenables you to manipulate the connection string as though it were a standard text string. In contrast, accessing the value as a property is usually simpler and safer.When you are finished viewing or manipulating the relevant value, return the value to the object by calling
SetStringor by setting the appropriate property.When you are finished, save your changes to secondary storage by calling
Save.The following code example demonstrates how to retrieve, change, and save connection string data.
static System.Exception ChangeCommentInUDL(string connString, string newComment)
{
try
{
IConnectionString udl = DB2OleDbConnectionString.ReadUDL(connString);
udl.Comment = newComment;
udl.Save();
System.Exception noException = null;
return noException;
}
catch (System.Exception ex)
{
return ex;
}
}