DSN mysql (VB)

Its ok.
But i cant create a new dsn for odbc with code vbnet without to go in administrator tools and odbc (new dsn).

This is connection string:
Code:
sConnectionString = " Driver={mySQL};Server=SERVERNAME;Port=3306;Option=131072;Database=MYDB
;Uid=USERNAME;Pwd=PASSWORD

but i cant create a new dsn
Thanks
 
You cant create with this connection string? you need to change some values of it like "SERVERNAME", "MYDB", "USERNAME", "PASSWORD" regarding your database setting.

And, sorry, there is no space in front of "Driver"
 
you could create new dsn over some Registry entery !!
HKEY_LOCAL_MACHINE --> Software --> ODBC --> ODBC.INI !!
If you are intested for this solution let me know!!


:D
 
Code:
Imports System
Imports System.Environment
...
...
...

Dim key, key1 As RegistryKey
        Dim subkey, subkey1 As RegistryKey

        key = Registry.LocalMachine
        subkey = key.CreateSubKey("SOFTWARE\ODBC\ODBC.INI\NEWDSN") Line AB
        subkey.SetValue("database", "wbamar")  your dbname
        subkey.SetValue("description", "") default
        subkey.SetValue("driver", SystemDirectory.ToString & "\" & "myodbc.dll") driver for mySQL
        subkey.SetValue("option", "0")  default 0
        subkey.SetValue("password", "") your pass
        subkey.SetValue("port", "3306") default is 3306
        subkey.SetValue("server", "MYCOMP")  name of server/computer or localhost
        subkey.SetValue("stmt", "") default
        subkey.SetValue("user", "root") your uname

        key.Close()
        subkey.Close()



        key1 = Registry.LocalMachine
        subkey1 = key.OpenSubKey("SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", True)
        subkey1.SetValue("NEWDSN", "MySQL") first value must me 
same as name in line  Line AB

        key1.Close()
        subkey1.Close()

:D
 
Last edited by a moderator:
yes,
Code:
key1 = Registry.LocalMachine
        subkey1 = key.OpenSubKey("SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", True)
        subkey1.SetValue("NEWDSN", "MySQL ODBC 3.51 Driver") first value must me 
same As Name In Line  Line AB
 
Excuse me i have the file odbc.ini in directory windows so i write:

Code:
 subkey = key.CreateSubKey("windows\ODBC.INI\NEWDSN")

but
the error is
An unhandled exception of type System.IO.IOException occurred in mscorlib.dll

Additional information: The parameter is incorrect.
 
with code that i post, your are modifing windows registry not file

so type exacty as i post except nname.pass,database...blah..

go to start --> Run -->type -->Regedit
and then check keys HKEY_LOCAL_MACHINE --> SOFTWARE --> ODBC --> ODBC.INI
 
Thank you, i see that u write but not add a new dsn.
I change:

subkey.SetValue("server", "localhost")
 
Back
Top