VB6 ADO upgrade to .NET

For a start, before you upgrade your old solution to .NET you might consider to use ArtinSoft’s Visual Basic Upgrade Companion (VBUC) instead of the Visual Studio build upgrade. I have not tried it, but using it might make the following advices superfluous.

To ease the upgrade of VB6 it is possible to keep old VB6 ADO in .NET.
Microsoft has made some Primary Interop Assemblies (PIA’s) that are tweeked in a .NET way, so they are to prefer compared to generating them yourself.

If they are installed on your machine you should be able to pick a reference to ADODB directly from the .NET tab.

As you can see on my machine they have been installed into C:\Program Files\Microsoft.NET\Primary Interop Assemblies\ and into two office directories.
I don’t know which installations installed them.

If those PIA’s are not on your production mashine you can deploy them either by following some trics in those two links:
http://support.microsoft.com/default.aspx/kb/318559
http://support.microsoft.com/default.aspx/kb/321688

Or you can manually copy them to the target machine and drop them into the assembly dir: %windir%\assembly\
Note: the underlying MDAC is not installed together with the PIA’s in either way.
You can check on the version of your MDAC by checking the version of this file: C:\Program Files\Common Files\System\ado\msado15.dll

When you compile the code in .NET you still might get some errors.
One could be this one:
http://searchwindevelopment.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid8_gci994379,00.html

In runtime there can be these errors:

Problem: An output value from a stored procedure returns nothing.

It happens in the case where: The stored procedure doesn’t return a recordset like here:

CREATE Procedure LookUpCountry
 /* Param List */
@CountryName Varchar(30),
@CountryValue int output
AS
select @CountryValue = Id from Country Where Name = @CountryName

It has to be told ADODB, that there is no recordset to return. Add parameter to the Execute method:

Call oCmd.Execute(, , ADODB.ExecuteOptionEnum.adExecuteNoRecords)

Problem: The recordset is serverside (connected).

By default in VB6 the recordset runs in disconnected mode (clientside). In VB.NET it runs in connected mode by default.

The connection must be set to disconnected mode explicit:

oConn = New ADODB.Connection
oConn.CursorLocation = ADODB.CursorLocationEnum.adUseClient
oConn.Open(...)

You might also want to read my other VB6 articles.

The End.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: