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. Can't create SqlConnection from CString [modified]

Can't create SqlConnection from CString [modified]

Scheduled Pinned Locked Moved Database
databasehelpcsharp
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. -- modified at 14:32 Friday 20th April, 2007

    D 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. -- modified at 14:32 Friday 20th April, 2007

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      It failed because the connection string you provided it, "Hello", isn't a valid description of what kind and which database you want to connect to. You might want to have a look at ConnectionStrings.com[^] for many examples of what connection strings for various databases are supposed to look like. My C++ is really rusty, but it loks like you need to back away from the database stuff for now and start by learning the basics of CLI before you jump into the deeper end of the .NET Pool.

      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      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