Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. DSN Creation through SQLConfigDataSource() funciton

DSN Creation through SQLConfigDataSource() funciton

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Durga_Devi
    wrote on last edited by
    #1

    Hi, The following sample failed to create the DSN, void main() { //As my DB path will change frequently i am using this method. bool aDSNCreated = false; char temp[MAX_PATH]; sprintf(temp,"DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver (*.mdb)\0", temp); printf("%d",aDSNCreated ); } whereas when I execute the below code; it execute successfully.Can anyone help in this why its happening? void main() { bool aDSNCreated = false; aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver(*.mdb)\0","DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); printf("%d",aDSNCreated ); }

    M D 2 Replies Last reply
    0
    • D Durga_Devi

      Hi, The following sample failed to create the DSN, void main() { //As my DB path will change frequently i am using this method. bool aDSNCreated = false; char temp[MAX_PATH]; sprintf(temp,"DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver (*.mdb)\0", temp); printf("%d",aDSNCreated ); } whereas when I execute the below code; it execute successfully.Can anyone help in this why its happening? void main() { bool aDSNCreated = false; aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver(*.mdb)\0","DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); printf("%d",aDSNCreated ); }

      M Offline
      M Offline
      Moak
      wrote on last edited by
      #2

      DurgaDevi_hr wrote:

      "Microsoft Access Driver(*.mdb)\0","DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"

      Interesting string format with a double Null-Terminator[^], what were they thinking? The extra Null-Terminator will cause problems with most C-Runtime string functions. Have a look at SQLConfigDataSource attributes with variables[^], does this help? /M

      Webchat in Europe :java: (only 4K)

      D 1 Reply Last reply
      0
      • M Moak

        DurgaDevi_hr wrote:

        "Microsoft Access Driver(*.mdb)\0","DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"

        Interesting string format with a double Null-Terminator[^], what were they thinking? The extra Null-Terminator will cause problems with most C-Runtime string functions. Have a look at SQLConfigDataSource attributes with variables[^], does this help? /M

        Webchat in Europe :java: (only 4K)

        D Offline
        D Offline
        Durga_Devi
        wrote on last edited by
        #3

        Hi Moak, I tried the logic as specified in the link. It worked fine. Thanks for that. But can u tell me, why SQLConfigDataSource() parameter alone is accepting the null terminator string? Any idea about that? :)

        M 1 Reply Last reply
        0
        • D Durga_Devi

          Hi Moak, I tried the logic as specified in the link. It worked fine. Thanks for that. But can u tell me, why SQLConfigDataSource() parameter alone is accepting the null terminator string? Any idea about that? :)

          M Offline
          M Offline
          Moak
          wrote on last edited by
          #4

          DurgaDevi_hr wrote:

          But can u tell me, why SQLConfigDataSource() parameter alone is accepting the null terminator string?

          In a nutshell, the SQLConfigDataSource() uses a strange string format and with a literal text string this is fortunately not a problem (your second example code). But when you use string functions such as sprintf/strcpy/strlen they will stop at the first Null-Terminator. For example "bla\0fasel\0" would be copied only to the the first \0 and becomes "bla\0". You can try it in the debugger. :)

          Webchat in Europe :java: (only 4K)

          modified on Monday, December 14, 2009 7:53 AM

          D 1 Reply Last reply
          0
          • M Moak

            DurgaDevi_hr wrote:

            But can u tell me, why SQLConfigDataSource() parameter alone is accepting the null terminator string?

            In a nutshell, the SQLConfigDataSource() uses a strange string format and with a literal text string this is fortunately not a problem (your second example code). But when you use string functions such as sprintf/strcpy/strlen they will stop at the first Null-Terminator. For example "bla\0fasel\0" would be copied only to the the first \0 and becomes "bla\0". You can try it in the debugger. :)

            Webchat in Europe :java: (only 4K)

            modified on Monday, December 14, 2009 7:53 AM

            D Offline
            D Offline
            Durga_Devi
            wrote on last edited by
            #5

            Tanx for ur reply!!

            1 Reply Last reply
            0
            • D Durga_Devi

              Hi, The following sample failed to create the DSN, void main() { //As my DB path will change frequently i am using this method. bool aDSNCreated = false; char temp[MAX_PATH]; sprintf(temp,"DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver (*.mdb)\0", temp); printf("%d",aDSNCreated ); } whereas when I execute the below code; it execute successfully.Can anyone help in this why its happening? void main() { bool aDSNCreated = false; aDSNCreated = SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, "Microsoft Access Driver(*.mdb)\0","DSN=SAMPLE\0DBQ=D:\\SAMPLE.mdb\0"); printf("%d",aDSNCreated ); }

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              DurgaDevi_hr wrote:

              The following sample failed to create the DSN,

              So then why aren't you calling SQLInstallerError() to find out why?

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups