How to deploy a Visual Basic .NET application that uses ADO interop (321688)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • ActiveX Data Objects (ADO) 2.7
  • ActiveX Data Objects (ADO) 2.6

This article was previously published under Q321688
Caution ADO and ADO MD have not been fully tested in a Microsoft .NET Framework environment. They may cause intermittent issues, especially in service-based applications or in multithreaded applications. The techniques that are discussed in this article should only be used as a temporary measure during migration to ADO.NET. You should only use these techniques after you have conducted complete testing to make sure that there are no compatibility issues. Any issues that are caused by using ADO or ADO MD in this manner are unsupported. For more information, see the following article in the Microsoft Knowledge Base:

840667 You receive unexpected errors when using ADO and ADO MD in a .NET Framework application

SUMMARY

This step-by-step article describes how to deploy a Visual Studio .NET project that uses the primary interop assembly (PIA) for ActiveX Data Objects (ADO) by using Microsoft Visual Basic. NET projects as an example.

The PIA for ADO (Adodb.dll) is a wrapper. You can use the PIA for ADO to use earlier versions of ADO, which are Component Object Model-based, in a Visual Studio .NET project. Microsoft strongly recommends that you use the ADO PIA because the ADO PIA helps to avoid certain problems with ADO and .NET COM interoperability (for example, problems with marshaling or garbage collection). The ADO PIA is not a part of the Microsoft .NET Framework but is included with Visual Studio .NET.

back to the top

Create a Simple ADO Interop Windows Application Project in Visual Basic .NET

  1. To create a new Windows Application project that is named Q321688_WinForm, follow these steps:
    1. Start Visual Studio .NET.
    2. On the File menu, point to New, and then click Project.
    3. Click Visual Basic Projects under Project Types, and then click Windows Application under Templates.
    4. In the Name box, type Q321688_WinForm.
  2. On the Project menu, click Add Reference.
  3. On the .NET tab, double-click adodb, and then click OK.
  4. Add the following code to connect to a computer that is running Microsoft SQL Server to test that ADO is working:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim con As New ADODB.Connection()
        Dim rs As New ADODB.Recordset()
        con.Provider = "SQLOLEDB"
        con.Open("Data Source=(local);Initial Catalog=pubs;Integrated Security=SSPI;")
        rs.Open("SELECT * FROM jobs", con, ADODB.CursorTypeEnum.adOpenStatic,_
            ADODB.LockTypeEnum.adLockReadOnly, ADODB.CommandTypeEnum.adCmdText)
        MessageBox.Show(rs(0).Value, "Testing ADODB PIA")
        rs.Close()
        con.Close()
        rs = Nothing
        con = Nothing
    End Sub
  5. Modify the connection string as necessary for your environment.
  6. Run the project to test ADO connectivity.
back to the top

Create a Simple ADO Interop Web Application Project in Visual Basic .NET

  1. To create a new Web Application project that is named Q321688_ASPNET, follow these steps:
    1. Start Visual Studio .NET.
    2. On the File menu, point to New, and then click Project.
    3. Click Visual Basic Projects under Project Types, and then click ASP.NET Web Application under Templates.
    4. In the Name box, type Q321688_ASPNET.
  2. On the Project menu, click Add Reference.
  3. On the .NET tab, double-click adodb, and then click OK.
  4. Add the following code to connect to a computer that is running Microsoft SQL Server to test that ADO is working:
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim con As New ADODB.Connection()
        Dim rs As New ADODB.Recordset()
        con.Provider = "SQLOLEDB"
        con.Open("Data Source=(local);Initial Catalog=pubs;Integrated Security=SSPI;")
        rs.Open("SELECT * FROM jobs", con, ADODB.CursorTypeEnum.adOpenStatic, _
            ADODB.LockTypeEnum.adLockReadOnly, ADODB.CommandTypeEnum.adCmdText)
        Page.Response.Write("Testing ADODB PIA: " & rs(0).Value)
        rs.Close()
        con.Close()
        rs = Nothing
        con = Nothing
    End Sub
  5. In Solution Explorer, in the References window, click adodb, and then change the Copy Local property to True.
  6. Modify the connection string as necessary for your environment.
  7. Run the project to test ADO connectivity.
back to the top

Create the Deployment Project in Visual Studio .NET

  1. To create a new deployment project, follow these steps:
    1. On the File menu, point to New, and then click Project.
    2. Click Setup and Deployment Projects under Project Types, and then click Setup Project under Templates.
    3. In the Name box, type Q321688Setup.
    4. Click Add to Solution, and then click OK.
  2. On the Project menu, point to Add, and then click Project Output.
  3. Click either Q321688_WinForm or Q321688_ASPNET in the Project list, click Primary Output in the list box, and then click OK. Notice that the Detected Dependencies node in Solution Explorer contains the following items:

    • adodb.dll
    • dotnetfxredist_x86_enu.msm

    In the Properties window, notice that the Exclude property of dotnetfxredist_x86_enu.msm is set to True.
  4. On the Build menu, click Build Q321688Setup. Notice that the Output window displays the location of the Microsoft Installer (.msi) file and other files that are created for deployment.
back to the top

Test the Deployment Project

  1. Open the Q321688Setup\Debug folder, and then run the Setup.exe file to install the application.
  2. Run the application to test it.
back to the top

Troubleshooting

  1. Verify that the Microsoft .NET Framework is installed.For additional information%1, click the article number%2 below to view the article%2 in the Microsoft Knowledge Base:

    324168 HOW TO: Deploy an Assembly to the Global Assembly Cache on the Target Computer

  2. Verify that you have the Microsoft PIA for ADODB (Adodb.dll version 7.0.9466.0).
  3. Verify that Microsoft Data Access Components (MDAC) is installed. MDAC is not included with the .NET Framework. You can use Component Checker to verify that MDAC is installed correctly. To download Component Checker, visit the following Microsoft Web site:
back to the top

REFERENCES

For additional information about how to redistribute the Microsoft .NET Framework, click the article number below to view the article in the Microsoft Knowledge Base:

315914 PRB: Error Message When You Install a Setup Generated by .NET Deployment: Error Installing Component

For additional information about how to use the PIA in Visual Studio .NET, click the article number below to view the article in the Microsoft Knowledge Base:

318559 INFO: Using the Primary Interop Assembly for ADO (ADODB) in Visual Studio .NET

For more information about the role and the use of primary interop assemblies, visit the following Microsoft Developer Network (MSDN) Web site: For more information about .NET interop, visit the following MSDN Web site: back to the top

Modification Type:MajorLast Reviewed:6/15/2006
Keywords:kbHOWTOmaster KB321688 kbAudDeveloper