Microsoft KB Archive/321688

= How to deploy a Visual Basic .NET application that uses ADO interop =

Article ID: 321688

Article Last Modified on 5/8/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft ActiveX Data Objects 2.7
 * Microsoft ActiveX Data Objects 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



IN THIS TASK
SUMMARY
 * Create a Simple ADO Interop Windows Application Project in Visual Basic .NET
 * Create a Simple ADO Interop Web Application Project in Visual Basic .NET
 * Create the Deployment Project in Visual Studio .NET
 * Test the Deployment Project
 * Troubleshooting

REFERENCES



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
 To create a new Windows Application project that is named Q321688_WinForm, follow these steps:  Start Visual Studio .NET. On the File menu, point to New, and then click Project. Click Visual Basic Projects under Project Types, and then click Windows Application under Templates. In the Name box, type Q321688_WinForm . </li> On the Project menu, click Add Reference.</li> On the .NET tab, double-click adodb, and then click OK.</li>  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 = &quot;SQLOLEDB&quot; con.Open(&quot;Data Source=(local);Initial Catalog=pubs;Integrated Security=SSPI;&quot;) rs.Open(&quot;SELECT * FROM jobs&quot;, con, ADODB.CursorTypeEnum.adOpenStatic,_       ADODB.LockTypeEnum.adLockReadOnly, ADODB.CommandTypeEnum.adCmdText) MessageBox.Show(rs(0).Value, &quot;Testing ADODB PIA&quot;) rs.Close con.Close rs = Nothing con = Nothing End Sub </li> Modify the connection string as necessary for your environment.</li> Run the project to test ADO connectivity.</li></ol>

back to the top

Create a Simple ADO Interop Web Application Project in Visual Basic .NET
 To create a new Web Application project that is named Q321688_ASPNET, follow these steps:  Start Visual Studio .NET.</li> On the File menu, point to New, and then click Project.</li> Click Visual Basic Projects under Project Types, and then click ASP.NET Web Application under Templates.</li> In the Name box, type Q321688_ASPNET .</li></ol> </li> On the Project menu, click Add Reference.</li> On the .NET tab, double-click adodb, and then click OK.</li>  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 = &quot;SQLOLEDB&quot; con.Open(&quot;Data Source=(local);Initial Catalog=pubs;Integrated Security=SSPI;&quot;) rs.Open(&quot;SELECT * FROM jobs&quot;, con, ADODB.CursorTypeEnum.adOpenStatic, _       ADODB.LockTypeEnum.adLockReadOnly, ADODB.CommandTypeEnum.adCmdText) Page.Response.Write(&quot;Testing ADODB PIA: &quot; & rs(0).Value) rs.Close con.Close rs = Nothing con = Nothing End Sub </li> In Solution Explorer, in the References window, click adodb, and then change the Copy Local property to True.</li> <li>Modify the connection string as necessary for your environment.</li> <li>Run the project to test ADO connectivity.</li></ol>

back to the top

Create the Deployment Project in Visual Studio .NET
<ol> <li>To create a new deployment project, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>On the File menu, point to New, and then click Project.</li> <li>Click Setup and Deployment Projects under Project Types, and then click Setup Project under Templates.</li> <li>In the Name box, type Q321688Setup .</li> <li>Click Add to Solution, and then click OK.</li></ol> </li> <li>On the Project menu, point to Add, and then click Project Output.</li> <li>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:

<ul> <li>adodb.dll</li> <li>dotnetfxredist_x86_enu.msm</li></ul>

In the Properties window, notice that the Exclude property of dotnetfxredist_x86_enu.msm is set to True.</li> <li>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.</li></ol>

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
<ol> <li>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

</li> <li>Verify that you have the Microsoft PIA for ADODB (Adodb.dll version 7.0.9466.0).</li> <li>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:

http://msdn.microsoft.com/dataaccess

</li></ol>

back to the top

<div class="references_section">