Pritesh
Pritesh

Reputation: 1970

How to Edit user DSN Programmatically in .Net?

We have many end users having DSN on their machine to connect to our SQL Server through Excel.

enter image description here

Now we have migrated our SQL Server and DSN needs to be edited to below value (From PrevSQLServer to NewSQLServer)

enter image description here

This change needs to be done on many End users machine so we thought we will make a kind of .exe file which we will just ask end user to double click and DSN will get edited.

We thought about .Net (as Windows machine by default have .net framework) to implement above .exe, on Google I realize that this needs to be done by editing registry so went in regedit but there I just do not see SQL Server name (attribute to be edited)

enter image description here

Where I can find SQL Server name in regedit which I can change programmatically? If yes how?

I even read about some ODBC file that can be edited to do this (instead of messing up with regedit)

I found a file ODBC.INI which had entry like

MIX_SQL_PROD=SQL Server (32 bit)

But there is no SQL Server name in that file.

How can I do this work of editing DSN? On Internet I found some code in power shell but not sure about using it as I do not have any expertise with Power shell and not sure PowerShell run time is available on windows machine by default

Upvotes: 1

Views: 639

Answers (2)

Ben Thul
Ben Thul

Reputation: 32737

Two things:

  1. You can use group policy to push out your DSN changes
  2. As long as you're changing it, change it to use a CNAME so that future moves (and there will be future moves) are just a DNS change in one place rather than the myriad client machine changes that you'll need to track down.

Upvotes: 1

dean
dean

Reputation: 10098

User DSNs are listed in registry under this key:

HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC Data Sources

Detail data about a specific DSN are kept here:

HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\<DSN name>

You can easily export the info into a reg file and simply import it into users registry.

Upvotes: 1

Related Questions