News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

Odbc Management Component - Programtically create DSN entries

Started by dhilipkumar, Nov 04, 2008, 09:19 PM

Previous topic - Next topic

dhilipkumar

                         OdbcNetTools - V1.0
Odbc Management Component - Programtically create DSN entries

Introduction

OdbcNetTools is a library developed to accomplish the following tasks in your Microsoft .Net applications.

Get list of DSNs on your system.
Get list of all ODBC drivers installed on your system.
Create a new DSN (System as well as user).
Delete an existing DSN (System as well as user).
This library gives you the flexibility of accomplishing the tasks of "ODBC Data Source Administrator" programmatically. The library has very easy to use interfaces that you can use in any of your .Net applications (Windows or ASP.Net). You will find this library very useful in your setup application where you need to create DSN on the fly.

How to create CreateNewDSN

The following code snippet shows you how to create a new DSN entry for SQL server.

[C#]


SqlServerDSNEntry entry = new SqlServerDSNEntry();
entry.Driver = "SQL Server";
entry.Name = "OdbcNetTool_DSN";
entry.Description = "FooBar";
entry.DBName = "Pardesi";
entry.Server = "localhost";
entry.TrustedConnection = false;
entry.LogLongQueries = true;
entry.QueryLogFile = "C:\\MyQueries.log";
OdbcTools.CreateDSN(DSNTypes.SYSTEM_DSN, entry);



[VB]

Sub Main()
  Dim entry As DBaseDSNEntry = New DBaseDSNEntry()
  entry.Name = "Reporting"
  entry.Directory = "C:\\ReportingData"
  entry.Description = "This is adbase dsn for reporting application"
  entry.Driver = "Microsoft dBase Driver (*.dbf)"
  entry.PageTimeOut = 20
  entry.DBase5 = False
  OdbcTools.CreateDSN(DSNTypes.SYSTEM_DSN, entry)
End Sub   

How to remove existing DSN


The following code shows how you can remove and existing DSN from your system.

[C#]

SqlServerDSNEntry entry = new SqlServerDSNEntry();
entry.Name = "OdbcNetTool_DSN";
OdbcTools.RemoveDSN(DSNTypes.SYSTEM_DSN, entry);



[VB]

Sub Main()
  Dim entry As DBaseDSNEntry = New DBaseDSNEntry()
  entry.Name = "Reporting"
  OdbcTools.RemoveDSN(DSNTypes.SYSTEM_DSN, entry)
End Sub