Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dsn creation by VB Codeing

Posted on 2003-11-02
8
Medium Priority
?
289 Views
Last Modified: 2010-04-17
hello sir,

          can it be possible to create 'system dsn'
   with the programming,& can this dsn be connected with database automatically with coding. If Possible , please help me, i'm in great need.


  Thanks

                         Barsiwal m.k.
0
Comment
Question by:mkbarsiwal
  • 2
  • 2
8 Comments
 
LVL 19

Accepted Solution

by:
Fahad Mukhtar earned 336 total points
ID: 9669019
0
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 332 total points
ID: 9669111
Read
HOWTO: Create and Remove a DSN in Visual Basic
  http://support.microsoft.com/support/kb/articles/Q171/1/46.ASP
HOWTO: Programmatically Create a DSN for SQL Server with VB
  http://support.microsoft.com/support/kb/articles/Q184/6/08.ASP 

0
 
LVL 9

Assisted Solution

by:bhagyesht
bhagyesht earned 332 total points
ID: 9676474
Option Explicit
'Declarations
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
   (ByVal hwndParent As Long, ByVal fRequest As Long, _
   ByVal lpszDriver As String, ByVal lpszAttributes As String) _
   As Long

Private Const ODBC_ADD_SYS_DSN = 4






Public Function CreateSQLServerDSN(DSNName As String, _
   ServerName As String, Database As String) As Boolean

'PURPOSE: 'CREATES A SYSTEM DSN FOR AN SQL SERVER DATABASE
'PARAMETERS: 'DSNName = DSN Name
             'ServerName = Name of Server
             'Database = Database to Use
'RETURNS: True if successful, false otherwise
'EXAMPLE: CreateSQLServerDSN "MyDSN", "MyServer", "MyDatabase"

Dim sAttributes As String

sAttributes = "DSN=" & DSNName & Chr(0)
sAttributes = sAttributes & "Server=" & ServerName & Chr(0)
sAttributes = sAttributes & "Database=" & Database & Chr(0)
CreateSQLServerDSN = CreateDSN("SQL Server", sAttributes)

End Function

Public Function CreateAccessDSN(DSNName As String, _
  DatabaseFullPath As String) As Boolean

'PURPOSE: 'CREATES A SYSTEM DSN FOR AN ACCESS DATABASE
'PARAMETERS: 'DSNName = DSN Name
             'DatabaseFullPath = Full Path to .mdb file
'RETURNS: True if successful, false otherwise
'EXAMPLE: CreateAccessDSN "MyDSN", "C:\MyDb.mdb"

    Dim sAttributes As String
   
    'TEST TO SEE IF FILE EXISTS: YOU CAN REMOVE IF YOU
    'DON'T WANT IT
    If Dir(DatabaseFullPath) = "" Then Exit Function
   
sAttributes = "DSN=" & DSNName & Chr(0)
sAttributes = sAttributes & "DBQ=" & DatabaseFullPath & Chr(0)
CreateAccessDSN = CreateDSN("Microsoft Access Driver (*.mdb)", _
   sAttributes)

End Function

Public Function CreateDSN(Driver As String, Attributes As _
  String) As Boolean

'PURPOSE: CREATES A SYSTEM DSN
'PARAMETERS: 'Driver = DriverName
'ATTRIBUTES: 'Attributes; varies as a function
             'of the Driver
'EXAMPLE: Refer to Code Above

    CreateDSN = SQLConfigDataSource(0&, ODBC_ADD_SYS_DSN, _
      Driver, Attributes)
       
End Function
0
 
LVL 19

Expert Comment

by:Fahad Mukhtar
ID: 10319185
Split Points
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 10319704
My recommandation: split points between Desp, Dhaest and bhagyesht
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Simple Linear Regression

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question