none
newbie - clr enable from c++ application RRS feed

  • Question

  •  

    Hi,

     

    Running the script from the studio management interface is fine, but I need to be able to run it from the application written in C++.

     

     

    the script is:

    --------------------------------
    EXEC sp_configure 'clr enabled', 1
    GO
    RECONFIGURE WITH OVERRIDE
    GO
    --------------------------------

    but how does one "call" this from a c++ .net application?

    Wednesday, May 21, 2008 7:02 PM

Answers

  • Pretty much follow what you just did above...

    String ^myInsertQuery = "exec sp_configure 'clr enabled', 1; reconfigure with override";

    SqlCommand ^myC = gcnew SqlCommand(myInsertQuery );

    myC->CommandType = CommandType:Text;
    myC->Connection = myConnection;

    try

    {

    myC->Connection->Open();

    myC->ExecuteNonQuery();

    myC->Connection->Close();

    }



    something like that...



    John

    Thursday, May 22, 2008 6:48 PM

All replies

  • It depends on which database access interface you are going to use.
    You might chose amongst ODBC, OLEDB, ADO.

    See for instance
    Sample: ADOVC1 Simple ADO/VC++ Application

    You can also download
    Microsoft Data Access Components (MDAC) 2.8 Software Development Kit

    and look at the sample code included.
    Wednesday, May 21, 2008 7:31 PM
  • I appreciate the reference to mass qunatities of samples, but I tend to get lost in the woods.

     

    As a reference, my C++ app calls a C# stored procedure [CreatePointCS(acPointType, acPointName, acDevName)] in sql2005 thusly:

    ==============

    char acType[16];

    char *s = acType;

    String ^myInsertQuery = "CreatePointCS";

    SqlCommand ^myC = gcnew SqlCommand(myInsertQuery );

    myC->CommandType = CommandType:Tongue TiedtoredProcedure;

    myC->Connection = myConnection;

    strcpy_s( acType, DB_bintostr( pt_ripper->id.type ) );

    strcat_s( acType, "s" );

     

    String ^sType = gcnew String(acType );

    String ^sPtName = gcnew String(pt_ripper->id.label );

    String ^sDevName = gcnew String(sy_rec->id.label );

     

    myC->Parameters->AddWithValue( "@acPointType", sType );

    myC->Parameters->AddWithValue( "@acPointName", sPtName );

    myC->Parameters->AddWithValue( "@acDevName", sDevName );

    try

    {

    myC->Connection->Open();

    myC->ExecuteNonQuery();

    myC->Connection->Close();

    }

    ===========================

    Using this as a model, how would I compose and execute the script:

    ====

    EXEC sp_configure 'clr enabled', 1
    GO
    RECONFIGURE WITH OVERRIDE
    GO
    ====

    Thursday, May 22, 2008 3:07 PM
  • Pretty much follow what you just did above...

    String ^myInsertQuery = "exec sp_configure 'clr enabled', 1; reconfigure with override";

    SqlCommand ^myC = gcnew SqlCommand(myInsertQuery );

    myC->CommandType = CommandType:Text;
    myC->Connection = myConnection;

    try

    {

    myC->Connection->Open();

    myC->ExecuteNonQuery();

    myC->Connection->Close();

    }



    something like that...



    John

    Thursday, May 22, 2008 6:48 PM