VB .NET - Os novos provedores de dados .NET


A cada dia novos provedores de dados são lançados para a plataforma .NET . Vou relacionar os principais provedores de dados para a plataforma .NET existentes na atualidade.

  1. OLE DB .NET Data Provider
     System.Data.OleDb
    - download

Este provedor permite o uso nativo dos provedores OLE DB (Ex: Microsoft.JET.OLEDB.4.0) através do interop COM para o acesso a dados. Exemplos de strings de conexão:

Para IBM AS/400 OLE DB Provider

' VB.NET
Imports System.Data.OleDb
...
Dim oOleDbConnection As OleDbConnection
Dim sConnString As String = _
           "Provider=IBMDA400.DataSource.1;" & _
           "Data source=MeuAS400DbName;" & _
           "User Id=MeuNomeUsuario;" & _
           "Password=MinhaSenha"
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()

Para JET OLE DB Provider

' VB.NET
Imports System.Data.OleDb
...
Dim oOleDbConnection As OleDbConnection
Dim sConnString As String = _
         "Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source=C:\MeuPath\MeuJet.mdb;" & _
         "User ID=Admin;" & _
         "Password=" 
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()

Para Oracle OLE DB Provider

' VB.NET
Imports System.Data.OleDb
...
Dim oOleDbConnection As OleDbConnection
Dim sConnString As String = _
         "Provider=OraOLEDB.Oracle;" & _
         "Data Source=MeuOracleDB;" & _
         "User ID=MeuNomeUsuario;" & _
         "Password=MinhaSenha" 
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()

Para SQL Server OLE DB Provider

' VB.NET
Imports System.Data.OleDb
...
Dim oOleDbConnection As OleDbConnection
Dim sConnString As String = _
         "Provider=sqloledb;" & _ 
         "Data Source=MeuServerName;" & _
         "Initial Catalog=MeuBancoDados;" & _
         "User Id=MeuNomeUsuario;" & _
         "Password=MinhaSenha" 
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
  1. ODBC .NET Data Provider
     
    System.Data.ODBC
    - download

Provedor ODBC que permite o acesso a drivers ODBC nativos da mesma forma que o provedor OLE DB .NET .Exemplos de strings de conexão:

Para SQL Server ODBC Driver

' VB.NET
Imports System.Data.Odbc
...
Dim oODBCConnection As OdbcConnection
Dim sConnString As String = _
          "Driver={SQL Server};" & _
          "Server=MeuSQLServerName;" & _
          "Database=MeuBancoDados;" & _
          "Uid=MeuNomeUsuario;" & _
          "Pwd=MinhaSenha"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()

Para Oracle ODBC Driver

' VB.NET
Imports System.Data.Odbc
...
Dim oODBCConnection As OdbcConnection
Dim sConnString As String = _
         "Driver={Microsoft ODBC for Oracle};" & _
         "Server=OracleServer.world;" & _
         "Uid=MeuNomeUsuario;" & _
         "Pwd=MinhaSenha"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()

Para Access (JET) ODBC Driver

' VB.NET
Imports System.Data.Odbc
...
Dim oODBCConnection As OdbcConnection
Dim sConnString As String = _
         "Driver={Microsoft Access Driver (*.mdb)};" & _
         "Dbq=c:\somepath\Meudb.mdb;" & _
         "Uid=Admin;" & _
         "Pwd="
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()

Para os demais drivers ODBC

' VB.NET
Imports System.Data.Odbc
...
Dim oODBCConnection As OdbcConnection
Dim sConnString As String = "Dsn=MeuDsn;" & _
                            "Uid=MeuNomeUsuario;" & _
                            "Pwd=MinhaSenha"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()
  1. MySQLDirect .NET Data Provider
     CoreLab.MySql
    - download

Este provedor de dados permite o acesso ao banco de dados MySQL usando o protocolo de rede MySQL nativo ou o cliente MySQL sem usar OLE DB ou ODBC. Exemplo de string para conexão:

Usando VB.NET

Imports CoreLab.MySql

Dim oMySqlConn As MySqlConnection = New MySqlConnection() 
oMySqlConn.ConnectionString = "User ID=MeuNomeUsuario;" & _
                              "Password=MinhaSenha;" & _
                              "Host=localhost;" & _
                              "Port=3306;" & _
                              "Database=MeuBancoDados;" & _
                              "Direct=true;" & _
                              "Protocol=TCP;" & _
                              "Compress=false;" & _
                              "Pooling=true;" & _
                              "Min Pool Size=0;" & _
                              "Max Pool Size=100;" & _
                              "Connection Lifetime=0"
oMySqlConn.Open()

Usando C#

Using CoreLab.MySql;

MySqlConnection oMySqlConn = new MySqlConnection(); 
oMySqlConn.ConnectionString = "User ID=MeuNomeUsuario;" +
                              "Password=MinhaSenha;" +
                              "Host=localhost;" +
                              "Port=3306;" +
                              "Database=MeuBancoDados;" +
                              "Direct=true;" +
                              "Protocol=TCP;" +
                              "Compress=false;" +
                              "Pooling=true;" +
                              "Min Pool Size=0;" +
                              "Max Pool Size=100;" +
                              "Connection Lifetime=0"; 
oMySqlConn.Open();
  1. Oracle .NET Data Provider - From Microsoft
     System.Data.OracleClient
    - download

Este provedor permite o acesso a um banco de dados Oracle usando a chamada da interface Oracle (OCI). A versão Oracle 8i Release 3 (8.17) CLient ou superior precisa estar instalada para o provedor funcionar. (Este provedor esta incluido na versão 1.1 do .NET Framework). Exemplos de strings de conexão :

Usando C#:

Usando System.Data.OracleClient;
 
OracleConnection oOracleConn = new OracleConnection();
oOracleConn.ConnectionString = "Data Source=Oracle8i;" +
                               "Integrated Security=SSPI";
oOracleConn.Open();

Usando VB.NET:

Imports System.Data.OracleClient

Dim oOracleConn As OracleConnection = New OracleConnection()
oOracleConn.ConnectionString = "Data Source=Oracle8i;" & _
                               "Integrated Security=SSPI";
oOracleConn.Open()
  1. PostgreSQLDirect .NET Data Provider
     CoreLab.PostgreSql
    - download

Este provedor permite o acesso a um banco de dados PostgreSQL usando o procotolo nativo. Exemplo de string de conexão:

Usando C#

Using CoreLab.PostgreSql;

PgSqlConnection oPgSqlConn = new PgSqlConnection(); 
oPgSqlConn.ConnectionString = "User ID=MeuNomeUsuario;" +
                              "Password=MinhaSenha;" +
                              "Host=localhost;" +
                              "Port=5432;" +
                              "Database=MeuBancoDados;" +
                              "Pooling=true;" +
                              "Min Pool Size=0;" +
                              "Max Pool Size=100;" +
                              "Connection Lifetime=0";
oPgSqlConn.Open();

Usando VB.NET

Imports CoreLab.PostgreSql

Dim oPgSqlConn As PgSqlConnection = New PgSqlConnection() 
oPgSqlConn.ConnectionString = "User ID=MeuNomeUsuario;" & _
                              "Password=MinhaSenha;" & _
                              "Host=localhost;" & _
                              "Port=5432;" & _
                              "Database=MeuBancoDados;" & _
                              "Pooling=true;" & _
                              "Min Pool Size=0;" & _
                              "Max Pool Size=100;" & _
                              "Connection Lifetime=0"
oPgSqlConn.Open()
  1. SQL Server .NET Data Provider
     System.Data.SqlClient -
     

Permite a conexão com um banco de dados Microsoft SQL Server 7.0 ou 2000 . Para a versão Microsoft SQL Server 6.5 utilize o provedor OLE DB .NET.

Usando C#:

Using System.Data.SqlClient;
...
SqlConnection oSQLConn = new SqlConnection();
oSQLConn.ConnectionString = "Data Source=(local);" +
                            "Initial Catalog=MeuBancoDados;" +
                            "Integrated Security=SSPI";
oSQLConn.Open();

Usando VB.NET:

Imports System.Data.SqlClient
...
Dim oSQLConn As SqlConnection = New SqlConnection()
oSQLConn.ConnectionString = "Data Source=(local);" & _
                            "Initial Catalog=MeuBancoDados;" & _
                            "Integrated Security=SSPI"
oSQLConn.Open()

Conexão remota (via endereço IP):

oSQLConn.ConnectionString = "Network Library=DBMSSOCN;" & _
                            "Data Source=xxx.xxx.xxx.xxx,1433;" & _
                            "Initial Catalog=MeuBancoDados;" & _
                            "User ID=MeuNomeUsuario;" & _
                            "Password=MinhaSenha"

Boa conexão ,  e  , até a mais ver... ...


José Carlos Macoratti