PreviousData Provider for .NET Guide (9.1 revision 1) Next

Connecting to a Database

Show this topic in Library frames

Once your Pervasive.SQL data provider is installed, you can connect from your application to your database with a connection string. See Connection String Options for the Pervasive.SQL Provider for connection attributes.

The following example illustrates connecting to the database using the Pervasive.SQL data provider from an application developed in Visual Studio.NET, using C#.

  1. In the Solution Explorer, right-click References.
  1. Click Add Reference; then, select the Pervasive.SQL data provider in the component list. If the data provider is not in the component list, click Browse and navigate to the data provider assembly.


  2. Click OK. The Solution Explorer now includes the Pervasive.SQL data provider.


  3. Add the data provider's namespace to the beginning of your application, as shown in the following C# code fragment:
  4. // Access Pervasive.SQL 
    using System.Data; 
    using Pervasive.Data.SqlClient; 
    
  5. Add the connection information for your server and exception handling code.
try 
{ 
   DBConn = new PsqlConnection("ServerDSN=Demo01; 
			UID=test01; 
			PWD=test01; 
			Server=localhost;"); 
	DBConn.Open(); 
} 
catch (Exception ex) 
{ 
   MessageBox.Show(ex.Message);     
} 
  1. Close the connection.
  2. // Close the connection 
    DBConn.Close(); 
    

Chapter contents
Publication contents

Prev topic: Quick Start
Next topic: Defining Basic Connection Strings