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. General Programming
  3. C / C++ / MFC
  4. SqlConnection does't work with CString?????

SqlConnection does't work with CString?????

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpcsharpquestion
2 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.
  • R Offline
    R Offline
    Romiks
    wrote on last edited by
    #1

    Hi All, I am newbie for .net. I have created the simple console application and trying to create connection to SQL database. Here is my code for console app: #include "stdafx.h" #include "vcclr.h" #include "atlstr.h" #using "mscorlib.dll" #using "System.dll" #using "System.Data.dll" using namespace System; using namespace System::Data; using namespace System::Data::SqlClient; int _tmain(int argc, _TCHAR* argv[]) { CString hello("Hello"); gcroot m_SqlDbConnection = gcnew SqlConnection(gcnew String(hello)); return 0; } I have the following exeption An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll Additional information: Format of the initialization string does not conform to specification starting at index 0. on the string gcroot m_SqlDbConnection = gcnew SqlConnection(gcnew String(hello)); Please help me to resolve the problem or point me to the article. P.S. I found that CString defined as in the atlstr.h typedef CStringT< TCHAR, StrTraitATL< TCHAR, ChTraitsCRT< TCHAR > > > CAtlString; typedef CAtlString CString; Maybe it helps.

    M 1 Reply Last reply
    0
    • R Romiks

      Hi All, I am newbie for .net. I have created the simple console application and trying to create connection to SQL database. Here is my code for console app: #include "stdafx.h" #include "vcclr.h" #include "atlstr.h" #using "mscorlib.dll" #using "System.dll" #using "System.Data.dll" using namespace System; using namespace System::Data; using namespace System::Data::SqlClient; int _tmain(int argc, _TCHAR* argv[]) { CString hello("Hello"); gcroot m_SqlDbConnection = gcnew SqlConnection(gcnew String(hello)); return 0; } I have the following exeption An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll Additional information: Format of the initialization string does not conform to specification starting at index 0. on the string gcroot m_SqlDbConnection = gcnew SqlConnection(gcnew String(hello)); Please help me to resolve the problem or point me to the article. P.S. I found that CString defined as in the atlstr.h typedef CStringT< TCHAR, StrTraitATL< TCHAR, ChTraitsCRT< TCHAR > > > CAtlString; typedef CAtlString CString; Maybe it helps.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      I'm not sure why this isn't working. Try breaking it down to see what part is actually causing the exception: CString hello("Hello"); gcroot<String ^> HelloStr = gcnew String(hello); gcroot<SqlConnection ^> m_SqlDbConnection = gcnew SqlConnection(HelloStr); The System.String constructor should be using the LPCTSTR operator of CString so I expect it should work. Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      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