473,790 Members | 3,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4719
yeah throw away the DSN and put it in the connection string

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

<za***@construc tion-imaging.com> wrote in message
news:11******** **************@ j55g2000cwa.goo glegroups.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.LocalM achine
Dim conRegKey1 As String = "SOFTWARE\ODBC\ ODBC.INI\" & DSN
Dim conRegKey2 As String = "SOFTWARE\ODBC\ ODBC.INI\ODBC Data
Sources"

Try
regHandle = reg.CreateSubKe y(conRegKey1)
regHandle.SetVa lue("Database", DB_Name)
regHandle.SetVa lue("Descriptio n", Description)
regHandle.SetVa lue("Driver", Driver_Name)
regHandle.SetVa lue("Option", stroption)
regHandle.SetVa lue("Password", password)
regHandle.SetVa lue("Port", port)
regHandle.SetVa lue("Server", Server_Name)
regHandle.SetVa lue("Stmt", stmt)
regHandle.SetVa lue("User", userid)
regHandle.SetVa lue("LastUser", userid)
regHandle.Close ()
reg.Close()

regHandle = reg.CreateSubKe y(conRegKey2)
regHandle.SetVa lue(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
17577
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 to load making any kind linkage with my Access data virtually useless. I have the MySQL driver setup in as a USER DSN. The MySQL data is sitting out on a server and the Access database is running locally. The network connection is very...
3
3259
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 am basically wanting to make sure that the data access is displaying is the most current data on the server. Thanks.
4
2612
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 an Access 2002 table via ODBC. Receive the following error: ADODB.Recordset (0x800A0CB3) Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype. I have set the directory permissions on...
0
534
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 IIS 5 Access 2002 ASP page ODBC File DSN = "Twmp DBs" The error message on an SQL update is :Cannot update. Database or object is
4
10620
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 able to find on using the SQLConnectin, SQLDataAdapter and DataSet objects all point me to a forms application where you can visually modify the data the send the update,insert,delete commands. I have not been able to locate how to update or...
2
8658
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: http://groups.google.com/groups?q=RefreshLinkedTablesWithADOX()&hl=en&lr=&selm=qb1ctvcdoftenojhpp34lb6fjb9ss8qd9c%404ax.com&rnum=1 My code simply replaces the DSN, UID, PWD and DBQ values in the ADOXTable.Properties("Jet OLEDB:Link Provider String").Value string...
2
4815
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 sql server is my backend server. This error occured whenever i step through and when it reaches rs.update it jux hangs down there and thereafter it shwn the aforementioned error. I am using the RecordSet properties to add the values. Can I use...
4
2999
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 individually, is there any way to do an update to that data in the MSysQueries table. I need to update NAME1 Column SELECT MSysQueries.Name1 FROM MSysQueries WHERE (((MSysQueries.Attribute)=1));
0
9512
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9987
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7531
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.