CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 1999
    Posts
    3,332

    Create DSN with COM object

    there is an "ODBC driver & data source names functions" COM component in the references in my VB 6installation.

    Has anyone ever used the CreateDSN method of the ODBCTool.DSN object with success?

    No matter what I entered, it didn't create a DSN nor did it raise an error.


  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Create DSN with COM object

    This created a User DSN just Fine for me..

    private Sub Command1_Click()
    Dim oODBC as new ODBCTool.Dsn
    If oODBC.CreateDSN("VB Created User DSN", "SQL Server", "<MySQLServerName>", "<MySQLDBName>", "", "", "Created via VB6.0", true, "") then
    MsgBox "DSN Created Successfully"
    End If
    End Sub





    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: Create DSN with COM object

    your code works very well.
    Do you know how to change it to create a system DSN?


  4. #4
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Create DSN with COM object

    I haven't been successfull in creating a System DSN with the DAETools.dsn Object, but, I have found an alternative method:

    private Declare Function SQLConfigDataSource Lib "odbccp32.dll" (byval hwndParent as Long, byval fRequest as Integer, byval lpszDriver as string, byval lpszAttributes as string) as Long
    Const ODBC_ADD_SYS_DSN = 4

    private Sub Command1_Click()
    If SQLConfigDataSource(0&, ODBC_ADD_SYS_DSN, "SQL Server", "DSN=My System DSN" & Chr(0) & "Server=<MySQLServer>" & Chr(0) & "Database=<MyDB>" & Chr(0) & "UseProcForPrepare=Yes" & Chr(0) & "Description=VB Created System DSN" & Chr(0) & Chr(0)) then
    MsgBox "DSN Created"
    End If
    End Sub



    For More Information on how to use this DLL, check here on the MSDN Site: Http://msdn.microsoft.com/library/ps...k/odch3kit.htm

    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  5. #5
    Join Date
    May 1999
    Posts
    3,332

    Re: Create DSN with COM object

    OK, Thanks.
    I knew that one, but I was looking for a COM solution that I could use from an ASP.
    Funny, the ODBCDSNTool seems to be completely undocumented...


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured