• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1047
  • Last Modified:

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

0
ejr19592004
Asked:
ejr19592004
1 Solution
 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now