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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. ado, ms sql server 'text' columns

ado, ms sql server 'text' columns

Scheduled Pinned Locked Moved Database
helpdatabasesql-serversysadmin
5 Posts 2 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.
  • S Offline
    S Offline
    sstoyan
    wrote on last edited by
    #1

    i'm stuck im trying to save a text file to sql server(in a 'text' column ); have no problem with unicode text, but with non-unicode strings after saving to the sql server i read garbage from the columns here's my code _bstr_t bstr_text = adoStream->ReadText(adoStream->Size); // dumping bstr_text shows the text here in bstr_text is ok recSet->Fields->GetItem(item)->Value = bstr_text; // debugging down to Field20::PutValue shows that correct data is being put in the field

    M 1 Reply Last reply
    0
    • S sstoyan

      i'm stuck im trying to save a text file to sql server(in a 'text' column ); have no problem with unicode text, but with non-unicode strings after saving to the sql server i read garbage from the columns here's my code _bstr_t bstr_text = adoStream->ReadText(adoStream->Size); // dumping bstr_text shows the text here in bstr_text is ok recSet->Fields->GetItem(item)->Value = bstr_text; // debugging down to Field20::PutValue shows that correct data is being put in the field

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      If your source data is 8-bit character-oriented, you should use a text column and ensure that the client's thread locale is the same as the locale used by the column. If your source data is 16-bit character-oriented, use an ntext column. You should also use ntext if your client's locale will be different from the server's. If you're just interested in storing and retrieving a file with no conversions at all, use an image column to treat it as binary. Obviously you can't do full-text search on an image column. When you assign a char string to a _bstr_t, the conversion to Unicode is performed using the thread's default code page. When the opposite process occurs to store the data in the database, SQL Server uses the configured locale's code page. If the two settings don't match, the conversions may not be a round-trip. Stability. What an interesting concept. -- Chris Maunder

      S 1 Reply Last reply
      0
      • M Mike Dimmick

        If your source data is 8-bit character-oriented, you should use a text column and ensure that the client's thread locale is the same as the locale used by the column. If your source data is 16-bit character-oriented, use an ntext column. You should also use ntext if your client's locale will be different from the server's. If you're just interested in storing and retrieving a file with no conversions at all, use an image column to treat it as binary. Obviously you can't do full-text search on an image column. When you assign a char string to a _bstr_t, the conversion to Unicode is performed using the thread's default code page. When the opposite process occurs to store the data in the database, SQL Server uses the configured locale's code page. If the two settings don't match, the conversions may not be a round-trip. Stability. What an interesting concept. -- Chris Maunder

        S Offline
        S Offline
        sstoyan
        wrote on last edited by
        #3

        thank you, but i know all of this already. i think i found the problem: it turns out that whenever i call _bstr_t bstr_text = adoStream->ReadText(adoStream->Size); no matter if the file is unicode or not, the data is saved to the wide char member of _bstr_t so some hacking is needed to get correct results with C char* data

        M 1 Reply Last reply
        0
        • S sstoyan

          thank you, but i know all of this already. i think i found the problem: it turns out that whenever i call _bstr_t bstr_text = adoStream->ReadText(adoStream->Size); no matter if the file is unicode or not, the data is saved to the wide char member of _bstr_t so some hacking is needed to get correct results with C char* data

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          Yes, this is because ADO is an Automation interface designed for access from Visual Basic, and hence uses BSTRs throughout. It isn't really designed for use with C++. You can access char-based data directly, without intervening conversions to and from Unicode, using the OLE DB interfaces. Visual C++ supplies the OLE DB Consumer Templates, which can simplify the task somewhat. If you need to get char-oriented data back out of a BSTR, see WideCharToMultiByte. Stability. What an interesting concept. -- Chris Maunder

          S 1 Reply Last reply
          0
          • M Mike Dimmick

            Yes, this is because ADO is an Automation interface designed for access from Visual Basic, and hence uses BSTRs throughout. It isn't really designed for use with C++. You can access char-based data directly, without intervening conversions to and from Unicode, using the OLE DB interfaces. Visual C++ supplies the OLE DB Consumer Templates, which can simplify the task somewhat. If you need to get char-oriented data back out of a BSTR, see WideCharToMultiByte. Stability. What an interesting concept. -- Chris Maunder

            S Offline
            S Offline
            sstoyan
            wrote on last edited by
            #5

            thank you WideCharToMultiByte is exactly what i used

            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