Microsoft Knowledge Base Email Alertz

KBAlertz.com: (218600) - This article demonstrates how to programmatically use Data Links feature of the Microsoft Data Access Components in order to generate a connection string at run-time.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **


Community Site



We Send hundreds of thousands of emails using ASP.NET Email


ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 218600 - Last Review: July 13, 2004 - Revision: 4.2

How To Use Data Links to Create a Connection String at Run Time

This article was previously published under Q218600

SUMMARY

This article demonstrates how to programmatically use Data Links feature of the Microsoft Data Access Components in order to generate a connection string at run-time.

MORE INFORMATION

In version 2.0 of the Microsoft Data Access Components, Data Links were introduced. Data Link files are similar to ODBC DSN files, but allow you to select an OLE DB provider to connect to your database. With the OLE DB Provider for ODBC drivers, you can also connect to an ODBC data source.

Double-clicking on a Data Link file displays a set of property pages that allow you to build a connection string to connect to your database.

You can use this same functionality in your Visual Basic applications by following the steps listed below:
  1. Launch Visual Basic and open a new Standard Exe project. Form1 is created by default.
  2. Select References from the Project menu, and then select Microsoft OLE DB Service Component 1.0 Type Library from the list of available references.
  3. Add a CommandButton to your form.
  4. Add the following code to the Click event of your CommandButton:
    Private Sub Command1_Click()
        Dim objDataLink As New DataLinks
        Dim strConn As String
        
        strConn = objDataLink.PromptNew
        MsgBox "The connection string you created is:" & _
               vbCrLf & strConn
    End Sub
    					
  5. Run the project.
When you click the CommandButton, you will see the Data Links property pages. Once you have specified how you want to connect to your database and click the OK button, you'll see the connection string in a dialog box.

REFERENCES

For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
189680  (http://kbalertz.com/Feedback.aspx?kbNumber=189680/EN-US/ ) How To Use Data Link Files with ADO 2.0
244659  (http://kbalertz.com/Feedback.aspx?kbNumber=244659/EN-US/ ) How To Create a Data Link File with Windows 2000
309485  (http://kbalertz.com/Feedback.aspx?kbNumber=309485/EN-US/ ) How To Build a Connection String Programmatically in ADO.NET by Using Visual Basic .NET

APPLIES TO
  • Microsoft Data Access Components 2.0
  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
Keywords: 
kbhowto KB218600
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please