Link to home
Start Free TrialLog in
Avatar of BogdanGrama
BogdanGrama

asked on

Erase System DSN

How can i delete a system SQL Server DSN
from ODBC in a vb function

      Option Explicit
Private Const ODBC_ADD_DSN = 1        ' Add data source
Private Const ODBC_CONFIG_DSN = 2
Private Const ODBC_REMOVE_DSN = 3     ' Private Const vbAPINull As Long =0&      ' NULL Pointer

      'Function Declare

          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

and the function

      Dim intRet As Long
      Dim strDriver As String
      Dim strAttributes As String
      strDriver = "SQL Server"
      strAttributes = "DSN=DSN_TEMP" & Chr$(0)
      intRet = SQLConfigDataSource(vbAPINull, ODBC_REMOVE_DSN, _
      strDriver, strAttributes)
      If intRet Then
          MsgBox "DSN Deleted"
      Else
          MsgBox "Delete Failed"
      End If
 
can you send me another example








 
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

You could try to remove the registry settings directly, but your method is better.
Why do you ?
Avatar of BogdanGrama
BogdanGrama

ASKER

To test a DSN connection on a netwoark
I have to create a dsn first
If a user of app is sett a rong server name The DSN remains
I whant to erase him from odbc whit a functiuon for example.

the code is from a VB4 Function

Do you have another ideea
The registre is good
I am a little bit scheptic: app is going to work on nt

whit pleasure
Bogdan Grama
Finsiel Romania
Bucharest
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK Thanks
sorry thats what you have posted already