473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Update ODBC DSN Properties in VB.NET Code?

I have a DSN that I frequently have to change the default database. Is
there a way to do this in VB.NET code instead of having to go through
the setup wizard every time?

May 18 '06 #1
4 4674
yeah throw away the DSN and put it in the connection string

May 18 '06 #2
Try using an API call to SQLConfigDataSource; although this solution is not
specific to VB.Net, it will solve your problem.

<za***@construction-imaging.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
I have a DSN that I frequently have to change the default database. Is
there a way to do this in VB.NET code instead of having to go through
the setup wizard every time?

May 18 '06 #3
Private Function CreateDSN(ByVal DB_Name As String, _
ByVal DSN As String, _
ByVal Description As String, _
ByVal Driver_Name As String, _
ByVal userid As String, _
ByVal password As String, _
ByVal Server_Name As String, _
ByVal port As String, _
ByVal stroption As String, _
ByVal stmt As String _
) As Boolean

Dim lResult As Long
Dim hKeyHandle As Long
Dim msg1 As String

Dim regHandle As RegistryKey ' Stores the Handle to Registry in
which values need to be set

Dim reg As RegistryKey = Registry.LocalMachine
Dim conRegKey1 As String = "SOFTWARE\ODBC\ODBC.INI\" & DSN
Dim conRegKey2 As String = "SOFTWARE\ODBC\ODBC.INI\ODBC Data
Sources"

Try
regHandle = reg.CreateSubKey(conRegKey1)
regHandle.SetValue("Database", DB_Name)
regHandle.SetValue("Description", Description)
regHandle.SetValue("Driver", Driver_Name)
regHandle.SetValue("Option", stroption)
regHandle.SetValue("Password", password)
regHandle.SetValue("Port", port)
regHandle.SetValue("Server", Server_Name)
regHandle.SetValue("Stmt", stmt)
regHandle.SetValue("User", userid)
regHandle.SetValue("LastUser", userid)
regHandle.Close()
reg.Close()

regHandle = reg.CreateSubKey(conRegKey2)
regHandle.SetValue(DSN, "SQL SERVER")
regHandle.Close()
reg.Close()
Catch err As Exception

End Try
End Function
if there is an existing DSN, it will overwite it.

HTH

May 19 '06 #4
I should have known that this info was simply stored in the registry.
Thanks for the pointer and the sample code.

May 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
3
by: Kyle Arrington | last post by:
I have a network server with MySQL on it and I am trying to make access update the information it has in its linked table on startup or command. I know nearly nothing about macros or modules. I...
4
by: mr_wizard | last post by:
I haven't written ASP code to update an Access DB in years. Having a permission problem. Been working on it for hours, time to get some help. Running IIS 5 on an XP Pro system. ASP code to update...
0
by: mr_wizard | last post by:
I posted a message yesterday on my difficulty in updating an Access table. Yesterday the error response was permission related. I've gotten past that, but still cannot update the table. XP Pro...
4
by: James | last post by:
I'm stuck. I have created a console application that does its job of collecting the data I want it to however I am stuck on writing this data back to a database. All of the examples I have been...
2
by: Tim Frawley | last post by:
I am attempting to change the ODBC Link Provider String in an Access database linked to an Oracle server using ADOX in VB.NET. I created some code using the example from post:...
2
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
4
by: harshakusam | last post by:
1) Is there any way to update the data in this table(MSysQueries). I have a bunch of passthrough queries where I need to update the ODBC connection.Instead of updating the properties in each query...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.