Microsoft Knowledge Base Email Alertz

KBAlertz.com: (308075) - This article demonstrates how to use an OLE DB Universal Data Link (.udl) file to specify the connection string that an ADO.NET OleDbConnection object uses to establish a database connection. OLE DB Universal Data Link (.udl) files provide a...

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
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



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



Expert Web Design & Graphic Design
Design44.com

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
The ad says 3 - but 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: 308075 - Last Review: December 28, 2005 - Revision: 3.0

How to use Data Link files with the OleDbConnection object in Visual Basic .NET

This article was previously published under Q308075

On This Page

SUMMARY

This article demonstrates how to use an OLE DB Universal Data Link (.udl) file to specify the connection string that an ADO.NET OleDbConnection object uses to establish a database connection.

OLE DB Universal Data Link (.udl) files provide a convenient way to create and verify an ActiveX Data Objects (ADO) connection string that is used to connect to an OLE DB data source. The connection string information is persisted in a specific format to a file with the .udl extension.

You can reference a .udl file in the ConnectionString property of an ADO.NET OleDbConnection object to specify the connection string that the object should use to connect to a database. Use the File Name parameter of the connection string to specify the name of the .udl file that contains the connection string information.

Steps to build the sample

Follow these steps to create a Visual Basic .NET Console Application that uses a .udl file to specify the connection string information for an ADO.NET OleDbConnection object:
  1. Use the SQL Server OLE DB Provider to connect to one of your Microsoft SQL Server databases, and create a .udl file named Test.udl in the root folder of drive C. You can also use the Microsoft OLE DB Provider for Jet 4.0 to configure the .udl file to connect to a Microsoft Access 97 or 2000 database if you do not have access to a SQL Server database. For more information about how to create a .udl file, click the following article number to view the article in the Microsoft Knowledge Base:
    189680  (http://kbalertz.com/Feedback.aspx?kbNumber=189680/ ) How to use Data Link files with ADO
    NOTE: When you create the .udl file, make sure to select the Allow Saving Password option on the Connection tab.
  2. Test the connection from the .udl file.
  3. Open a new Visual Basic .NET Console Application.
  4. Replace the default code in the Module1 code module with the following code:
    Imports System.Data.OleDb
    Imports Console = System.Console
    
    Module Module1
    
        Sub Main()
    
            Dim response As String
    
            Dim cn As New OleDbConnection()
            cn.ConnectionString = "File Name=c:\test.udl"
            cn.Open()
            If cn.State = ConnectionState.Open Then
                Console.WriteLine("Connection opened successfully")
            Else
                Console.WriteLine("Connection could not be established")
            End If
            cn.Close()
            cn = Nothing
    
            response = Console.ReadLine()
    
        End Sub
    
    End Module
    					
  5. In the statement that sets the ConnectionString property of the OleDbConnection object, modify the path to the .udl file if you created it with a different name or persisted it to a different location.
  6. Run the application from within the Visual Studio .NET Integrated Development Environment (IDE). A console window should open and display the text, "Connection opened successfully!" to indicate that the OleDbConnection object was able to use the connection string information in the .udl file to establish the database connection.
  7. Press any key to dismiss the console window and stop the application.

REFERENCES

For more information, click the following article number to view the article in the Microsoft Knowledge Base:
244659  (http://kbalertz.com/Feedback.aspx?kbNumber=244659/ ) How to create a Data Link file with Windows 2000

APPLIES TO
  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft ADO.NET 1.1
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual Basic .NET 2003 Standard Edition
Keywords: 
kbhowtomaster kbsystemdata KB308075
       

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