Effective Database Name Handling Techniques

Estimated reading time: 2 minutes

DG for Visual Studio is adept at handling the standard “database name” conventions familiar to AVR programmers and users of tools such as DataGate Database Manager. A database name is simply a shorthand notation, redirecting the client-side engine to a set of client/server database connection parameters stored in the system registry. These registry entries can be accessed and manipulated with the SourceProfile object. SourceProfile provides the programmer with some of the functionality of DataGate Database Manager’s “Work with Database Names” option. The object constructor and methods Register and Unregister are used to retrieve, persist, and delete respectively, database name registry entries.

The following example retrieves a database name called “Asna 400 db” (in the process of constructing the SourceProfile object), changes the user and password, and then saves the changes by calling Register.

  using ASNA.DataGate.Providers;
  SourceProfile AsnaDbName;
  AsnaDbName = new SourceProfile("Asna 400 db");
  AsnaDbName.User = "NewUser";
  AsnaDbName.Password = "NewPasswd";
  AsnaDbName.Register()

To discover the currently registered database names available for use in a program, use the SourceProfile.GetNames static method. This method returns an array of strings as shown in the following example. This snippet of AVR code will print “*PUBLIC” and “User” database names registered on the machine where the code runs.

     Console.WriteLine( "*Public Database Names:" );
  Foreach Name(DbName) Collection(SourceProfile.GetNames(*True)) 
				Type(*String);
     Console.WriteLine( "  *Public\" + DbName );
  Endfor;
     Console.WriteLine( "User Database Names:" );
  Foreach Name(DbName) Collection(SourceProfile.GetNames(*False)) 
				Type(*String);
  Console.WriteLine( "  " + DbName );
  Endfor;

Console.WriteLine( “ “ + DbName ) Endfor <p> SourceProfile objects may be assigned to the AdgConnection.SourceProfile property to force a subsequent call to AdgConnection.Open to use the SourceProfile’s connection parameters. Changing AdgConnection.SourceProfile has no effect on the database connection of an AdgConnection object in the Open state. Rather, AdgConnection.SourceProfile is used by the AdgConnection.Open method to initialize the database connection.

See Also

Database Name Handling
AdgConnection Class
AdgConnection.Open Method
AdgConnection.SourceProfile Property
AdgConnection.State Property
SourceProfile Class
SourceProfile.Register Method
SourceProfile.GetNames Method
SourceProfile.Unregister Method