Modifying a file.dsn outside of the ODBC Control Panel

I have created a file DSN using the ODBC control panel. The file DSN appears under the 3rd tab inside the control panel. I have configured the file DSN to include the directory and format for the file.

I need to change the file DSN on the fly. I have gotten suggestions to use tools like Notepad or Wordpad which I have. The file opens up alright but once I modify the file in either Notepad or Wordpad the file becomes unreadable in the ODBC control panel with the following error:

“General Error: Invalid File DSN”

So I then reposted the question and I got the suggestion that if I opened the file via VB Data Environment I should be able to read and modify the file without a problem. Great. Can you see a way to modify a text in the Data Environment ? Because I define a new connection under the DE object and using the Microsoft OLE DB Provider for ODBC Drivers I create a link to the file VIA the file DSN that I originally created. I then add a command and select Table which in fact does show me the file. But once I try to drag that object onto a form I get the following error:

[Microsoft][ODBC Text Driver] Cannot Update DataBase or Object is read only.

Ok. So given that that avenue was closed I they tried to do the whole via the Filesystemobject in VB, as follows:

Sub ShowFileList()
   Const ForReading = 1, ForWriting = 2, ForAppending = 8
   Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
   Dim fso, tsIn, dsnIn, dsnOut
   'General Object
   Set fso = CreateObject("Scripting.FileSystemObject")
   'Read File
   Set dsnIn = fso.GetFile("C:\Program Files\Common Files\ODBC\Data Sources\WinpasTxtIn.dsn")
   Set tsIn = dsnIn.OpenAsTextStream(ForReading, TristateUseDefault)
   'Write File
   fso.CreateTextFile "C:\Program Files\Common Files\ODBC\Data Sources\WinpasTxtOut.dsn"
   Set dsnOut = fso.GetFile("C:\Program Files\Common Files\ODBC\Data Sources\WinpasTxtOut.dsn")
   Set tsOut = dsnOut.OpenAsTextStream(ForWriting, TristateUseDefault)
   Do While tsIn.AtEndOfStream <> True
      TextStream = tsIn.ReadLine
      tsOut.Write TextStream
   Loop
   tsIn.Close
   tsOut.Close
End Sub

So what’s happening here is the input file – dsnin – is not impacted in any way and is still accessible via the ODBC Control Panel. But the output file dsnout is corrupted with the same error as above:

“General Error: Invalid File DSN”


So what is going on here ? I mean there has to be a way to write out file DSN files outside of the ODBC control panel without encountering errors and corrupted files.

Any ideas ?

Thanks

Eddie

ejr19592004Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pique_techCommented:
It's done via editing the registry using Win32 API function calls.  Here's the how-to directly from Microsoft:  
     http://support.microsoft.com/default.aspx?scid=kb;en-us;171146
Here's another:
     http://support.microsoft.com/default.aspx?scid=kb;en-us;184608

I've used both and they seem to work as expected without incident, including being able to get to them via the "normal" ODBC configuration utility.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.