|
|
|
|
|
|
|
Author Rank :
|
|
|
Page Views :
|
3158
|
|
Downloads :
|
0
|
|
Rating :
|
Rate it
|
|
Level :
|
Beginner
|
|
|
Connecting through the ODBC Data Source Name (DSN) is another option to access a database using ODBC data providers. Using DSN is useful when you need to access different kinds of ODBC data sources and you don't know the user ID and passwords. You ask the user to create a DSN, or you create a DSN programmatically and ask the user to enter their UserId and password.
You can either create a DNS programmatically or create one manually using the ODBC Data Source Administrator. If you're using windows 2000, you go to Control Panel > Administrative Tools > Data Sources (ODBC). This brings up the ODBC Data Sources Administrator. Using this Administrator, you can create data sources, reconfigure them, and remove them. The ODBC Data Source Administrator looks like figure 5-26.

Figure 5-26. ODBC Data Source Administrator screens with add, remove, and configure options
As you can see from figure 5-26, you can add or remove new data source names or configure existing data source names using the Add, Remove, and Configure buttons. The Add button launches the Create New Data Source Wizard. On the first screen of this wizard, you can select the desired driver. As you can see form figure 5-27. I picked the Microsoft Access driver because I'm going to create a DSN for the Access database .

Figure 5-27. Selecting an ODBC driver for a new DSN
When you click Finish, the next step is to select a database name. On this screen, you can also create a new database or repair and compact an existing one. For this example, select the c:\Northwind Access 2000 database and give it the DSN name NWDSN (see figure 5-28).

Figure 5-28. Creating a DSN using the Norht wind Access database
Now you've created a DSN. Connecting to this DSN using an ODBC data provider is pretty simple. Instead of creating a connection string, you use the DSN as a connection string. Rest assured, everything is the same you've been doing so far.
As you can see from Listing 5-26, you can connect to an ODBC DSN using ODBC data providers.
Listing 5-26. Connecting to an ODBC DSN
' Create the Data Source Name connection string to ' acess our Data source Dim ConnectionString As String = " DSN =NWDSN" Dim conn As New OdbcConnection(ConnectionString)
' use the SQL Query to get the customers data Dim cmd As New OdbcCommand("Select * From customers", conn) conn.Open()
You can also access your other favorite databases, such as MySQL. You must have the MyODBC driver installed, but assuming you have everything set up that you need, you can use.NET to read this popular database. Listing 5-27 shows the code that will read the MySQL database through the Test DSN ODBC data source.
Conclusion
Hope this article would have helped you in understanding Connecting to a Data Source in ADO.NET. See my other articles on the website on ADO.NET.
|
|
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post
Here.
|
|
|
|
|
Login
to add your contents and source code to this article
|
|
|
|
|
|
|
|
|
|
|
|
Raj Kumar
Raj Kumar is a Microsoft MVP and Senior Software Engineer with lots of hands on experience using ASP.NET 2.0/3.5, AJAX, MVC, C#, Visual Basic .NET, SQL Server 2005/2008, Oracle, WPF, WCF, XAML and Silverlight. He has over 6 years of IT experience working most on Microsoft technologies. He holds Master's degree in Computer Science. When he is not writing code, he likes to write articles and play cricket.
Reach him at raj2511984@gmail.com
|
|
|
|
|
|
|
|
|
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional
consulting company, our consultants are well-known experts in .NET and many of them
are MVPs, authors, and trainers. We specialize in Microsoft .NET development and
utilize Agile Development and Extreme Programming practices to provide fast pace
quick turnaround results. Our software development model is a mix of Agile Development,
traditional SDLC, and Waterfall models.
|
|
Click here to learn more about C# Consulting. |
|
|
|
|
|
|
|
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon.
Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees.
As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
|
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
|
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
|
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
|
|
|
|
|
|
|
|
|
|
|
|
|