ADODB to SqlClient

Related Content

This upgrade technique ports the ADO code into ADO.NET using the System. Data.Sqlclient namespace.It can be used in the following scenarios:
  • ADO connecting to SQLserver: This solution generates helper-free source code, however, there are many functional details that require manual implementation. We recommend to use the previous option since most of the lost functionality is implemented into the helper classes.
  • ADO connecting to any other provider: when ADO is used to connect to any other data provider besides SQLserver (Jet, ODBC,…) this option CANNOT be used. The previous option must be compulsory used.

The member transformation for this data access technology is described as follows:

Class Maps To
ADOBD.Command System.Data.SqlClient.SqlCommand
ADOBD.Parameters System.Data.SqlClient.SqlParameterCollection
ADOBD.DataTypeEnum System.Data.DbType
ADOBD.ParameterDirectionEnum System.Data.ParameterDirection
ADOBD.Parameter System.Data.SqlClient.SqlParameter
ADOBD.RecordSet System.Data.DataSet
ADOBD.CommandTypeEnum System.Data.CommandType
ADOBD.Connection System.Data.SqlClient.SqlConnection
ADOBD.Error System.Data.SqlClient.SqlError
ADOBD.Errors System.Data.SqlClient.SqlErrorCollection
ADOBD.IsolationLevelEnum System.Data.IsolationLevel
ADOBD.ObjectStateEnum System.Data.ConnectionState

If the ADODB to SqlClient feature is enabled, the Profile Manager will automatically enable the ADODB-RDO... and ADOR to SqlClient features because of dependencies and requirements to upgrade some data access patterns.

A brief source sample of this feature:

Original VB6 Code:

Public recRecordset As ADODB.Recordset
Public ADODBConnection As New ADODB.Connection

Private Sub Form_Load()
   Set ADODBConnection = New ADODB.Connection

   ADODBConnection.ConnectionString = "provider=sqloledb;data source=AISCRIT11\FTT;initial catalog=Northwind;user id=ftt_uwee;password=fttuwee;"

   ADODBConnection.Open

   Set recRecordset = New ADODB.Recordset
   recRecordset.CursorLocation = adUseClient

   recRecordset.Open "select * from Customers", ADODBConnection, adOpenKeyset, adLockOptimistic, adCmdText

   recRecordset.Sort = "CustomerId"
   recRecordset.MoveFirst
End Sub

Resulting VB.NET Code:

Public recRecordset As DataSet
Private _ADODBConnection As SqlConnection = Nothing

Private Sub Form1_Load(ByVal eventSender As Object, ByVal eventArgs As EventArgs) Handles MyBase.Load
   ADODBConnection = New SqlConnection()
ADODBConnection.ConnectionString = "provider=sqloledb;data source=AISCRIT11\FTT;initial catalog=Northwind;user id=ftt_uwee;password=fttuwee;"
'UPGRADE_TODO: (7010) The connection string must be verified to fullfill the .NET data provider conecction string requirements. More Information: http://www.vbtonet.com/ewis/ewi7010.aspx
   ADODBConnection.Open()

   recRecordset = New DataSet()
'UPGRADE_ISSUE: (2064) ADODB.Recordset property recRecordset.CursorLocation was not upgraded. More Information: http://www.vbtonet.com/ewis/ewi2064.aspx
   UpgradeStubs.ADODB_Recordset.setCursorLocation(recRecordset, ADODB.CursorLocationEnum.adUseClient)
   Dim com As New SqlCommand
   com.Connection = ADODBConnection
   com.CommandText = "select * from Customers"
   Dim adap As SqlDataAdapter = New SqlDataAdapter(com.CommandText, com.Connection)
   recRecordset = New DataSet("dsl")
adap.Fill(recRecordset)
'UPGRADE_ISSUE: (2064) ADODB.Recordset property recRecordset.Sort was not upgraded. More Information: http://www.vbtonet.com/ewis/ewi2064.aspx
   UpgradeStubs.ADODB_Recordset.setSort(recRecordset, "CustomerId")
'UPGRADE_ISSUE: (2064) ADODB.Recordset method recRecordset.MoveFirst was not upgraded. More Information: http://www.vbtonet.com/ewis/ewi2064.aspx
   UpgradeStubs.ADODB_Recordset.MoveFirst(recRecordset)
End Sub

Resulting C#.NET Code:

public DataSet recRecordset = null
private SqlConnection _ADODBConnection = null

private void Form1_Load( Object eventSender, EventArgs eventArgs) 
{ 
ADODBConnection = new SqlConnection()

ADODBConnection.ConnectionString = "provider=sqloledb;data source=AISCRIT11\\FTT; initial catalog=Northwind;user id=ftt_uwee;password=fttuwee;" 

//UPGRADE_TODO: (7010) The connection string must be verified to fullfill the .NET data provider conecction string requirements. More Information: http://www.vbtonet.com/ewis/ewi7010.aspx 
ADODBConnection.Open()

   recRecordset = new DataSet()
//UPGRADE_ISSUE: (2064) ADODB.Recordset property recRecordset.CursorLocation was not upgraded. More Information: http://www.vbtonet.com/ewis/ewi2064.aspx 
UpgradeStubs.ADODB_Recordset.setCursorLocation(recRecordset, ADODB.CursorLocationEnum.adUseClient) 
SqlCommand com = new SqlCommand()
com.Connection = ADODBConnection 
com.CommandText = "select * from Customers"
SqlDataAdapter adap = new SqlDataAdapter(com.CommandText, com.Connection)
recRecordset = new DataSet("dsl") 
adap.Fill(recRecordset)

//UPGRADE_ISSUE: (2064) ADODB.Recordset property recRecordset.Sort was not upgraded. More Information: http://www.vbtonet.com/ewis/ewi2064.aspx 
UpgradeStubs.ADODB_Recordset.setSort(recRecordset, "CustomerId")
 
//UPGRADE_ISSUE: (2064) ADODB.Recordset method recRecordset.MoveFirst was not upgraded. More Information: http://www.vbtonet.com/ewis/ewi2064.aspx 
 UpgradeStubs.ADODB_Recordset.MoveFirst(recRecordset)
Talk To An Engineer