SunQuest
 
       Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - How to Use Data Sources with Databases
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

How to Use Data Sources with Databases
By: Murach Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2006-11-02

    Table of Contents:
  • How to Use Data Sources with Databases
  • How to start the Data Source Configuration Wizard
  • How to choose a data source type
  • How to create a connection to a database
  • How to choose database objects for a data source

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    How to Use Data Sources with Databases - How to create a connection to a database


    (Page 4 of 5 )

    After you choose the data source type, the Data Source Configuration Wizard displays a dialog box that lets you choose the data connection you want to use. From this dialog box, you can select an existing connection (one you’ve previously defined), or you can click the New Connection button to display the Add Connection dialog box. This dialog box helps you identify the database that you want to access and provides the information you need to access it. That includes specifying the name of the server that contains the database, entering the information that’s required to log on to the server, and specifying the name of the database. How you do that, though, varies depending on whether you’re running SQL Server Express on your own PC or whether you’re using a database server that’s running on a network server.

    If you’re using SQL Server Express on your own PC and you’ve downloaded and installed it as described in appendix A, you can use the localhost keyword to specify that the database server is running on the same PC as the application. This keyword should be followed by a backslash and the name of the database server: SqlExpress.

    For the logon information, you should select the Use Windows Authentication option. Then, SQL Server Express will use the login name and password that you use to log in to Windows as the name and password for the database server too. As a result, you won’t need to provide a separate user name and password in this dialog box.

    Last, you enter or select the name of the database that you want to connect to. In this figure, for example, the connection is for the MMABooks database that’s used throughout the chapters in this section of the book. When you’re done supplying the information for the connection, you can click the Test Connection button to be sure that the connection works.

    In contrast, if you need to connect to a database that’s running on a database server that’s available through a network, you need to get the connection information from the network or database administrator. This information will include the name of the database server, logon information, and the name of the database. Once you establish a connection to the database, you can use that connection for all of the other applications that use that database.

    By default, Visual Studio assumes you want to access a SQL Server database as shown here. This works for SQL Server 7, 2000, and 2005 databases including SQL Server Express databases. If you want to access a different type of database, though, you can click the Change button to display the Change Data Source dialog box. Then, you can select the data source and the data provider you want to use to access that data source. If you want to access an Oracle database, for example, you can select the Oracle Database item in the Data Source list. Then, you can choose the data provider for Oracle or the data provider for OLE DB from the Data Provider drop-down list.

    The Add Connection and Change Data Source dialog boxes Description

    Description

    1. By default, a connection uses the SQL Server data provider. If that isn’t what you want, you can click the Change button in the Add Connection dialog box to display the Change Data Source dialog box. Then, you can choose the right data source and data provider.
    2. To be sure that the connection is configured properly, you can click the Test Connection button in the Add Connection dialog box.
    3. The next dialog box (not shown) asks if you want to save the connection string to the application configuration file (app.config), and we recommend that you do that. Then, if the connection string changes later on, you can change the string in the app.config file rather than in each form that uses the connection string.

    Express Edition differences

    • The Change Data Source dialog box provides only two options: Microsoft Access Database File and Microsoft SQL Server Database File.
    • The Add Connection dialog box is simpler, and it includes a Database File Name text box that you use to specify the database. To do that, you click the Browse button to the right of the text box and use the resulting dialog box to point to the data file for the database.

    Figure 14-3.  How to create a connection to a database

    More Visual Basic.NET Articles
    More By Murach Publishing


       · This article is an excerpt from the book "Murach's Visual Basic 2005," published by...
     

    Buy this book now. This article is excerpted from chapter 14 of the book Murach's Visual Basic 2005, written by Anne Boehm (Murach, 2006; ISBN: 1890774383). Check it out today at your favorite bookstore. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway