SQL Server Table-Valued Parameters in c++ OLEDB client? - c++

I have an c++ application working ith SQL Server via OLEDB.
How to use table-valued parameters in old good unmanaged c++ OLEDB clients?
In NET app it is clear how to :
SqlParameter param = new SqlParameter("#Customers", dataTable);
param.SqlDbType = SqlDbType.Structured;
cmd.Parameters.Add(param);
// Execute the command
SqlDataReader rdr = cmd.ExecuteReader();
How to pass this kind of parameters calling stored procedures in c++ oledb client app?

Here's an example of doing it using ADO, is that what you're looking for? http://msftdpprodsamples.codeplex.com/wikipage?title=SS2008%21Readme_Table-Valued%20Parameters&referringTitle=Home

Related

Multithreading using C++ and Pro*C

We want to write a multi-threading application using C++ and Pro*c. I have written classes for spawning the threads and doing business logic. I am facing an issue while connecting to the database using Pro*C.
I don't see any way to write Pro*C code to get the SQL context back to the C++ layer and assign it to a thread. I searched google for examples and I see the entire threading logic being embedded in the Pro*C layer.
I am trying to code like below.
void getSqlContext(const char* userName, const char* password)
{
/*
declaring the variables.
sql_context ctx1;
*/
/*Enabling threads in proc.
opening a connection
*/
/*
returning sql_context
*/
}

MySQL C++ Connector: How do I get the thread/connection Id?

I'm trying to find out how to obtain the MySQL Connection/thread id using Connector C++.
mysql_thread_id(MYSQL* ) seems to be available for just this, but I'm not sure how to get an instance of MYSQL from the Connector C++.
What I've tried:
int threadId = mysql_thread_id(NULL);
But this just returns zero.
Any ideas?
The function mysql_thread_id() expects a pointer to a connection object created by the native MySQL C API's mysql_connect(...) function. Connector/C++ has buried that object very deep (I looked). The alternative suggested by MySQL's documentation here is to execute query SELECT CONNECTION_ID() and the returned result will be the ID you're looking for.

Issuing prepared/parameterized queries through libcouchbase-cxx

I'm brand new to couchbase, and I'm developing a client which needs to issue prepared/parameterized n1ql queries via the c++ client library (https://github.com/couchbaselabs/libcouchbase-cxx). Issuing static queries is straightforward, but I haven't been able to find the correct process for issuing prepared queries. Has anybody been able to do this?
Following doc/example shows how to use the prepared stmt.
http://developer.couchbase.com/documentation/server/4.5/sdk/c/n1ql-queries-with-sdk.html
https://github.com/couchbaselabs/devguide-examples/blob/server-4.5/c/query-placeholders.cc
// To enable using prepared (optimized) statements, you can use
// the LCB_CMDN1QL_F_PREPCACHE flag. This is equivalent to setting
// 'adhoc=False' in other SDKs
cmd.cmdflags |= LCB_CMDN1QL_F_PREPCACHE;
rc = lcb_n1p_mkcmd(params, &cmd);
rc = lcb_n1ql_query(instance, &rows, &cmd);
lcb_wait(instance);
-Prasad

Creating simple WebService in C++ / Qt (acting as server) providing JSON data

I need to create a simple web service (being the "server"). The goal is to provide some data I do read in an Qt / C++ application as JSON data. Basically a JavaScript application in the browser shall read its data from the Qt app. It is usually a single user scenario, so the user runs a Google Maps application in her browser, while additional data come from the Qt application.
So far I have found these libs:
Qxt: http://libqxt.bitbucket.org/doc/0.6/index.html but being a newbie on C++/Qt I miss some examples. Added: I have found one example here
gSoap: http://www.cs.fsu.edu/~engelen/soap.html has more examples and documentation and also seems to support JSON
KD SOAP: http://www.kdab.com/kdab-products/kd-soap/ with no example as far as I can tell, docu is here
Qt features itself, but it is more about acting as a client: http://qt-project.org/videos/watch/qt-networking-web-services
Checking SO gives me basically links to the above libs
webservice with Qt with an example I do not really get.
How to Create a webservice by Qt
So basically I do have the following questions:
Which lib would you use? I want to keep it as simple as possible and would need an example.
Is there another (easy!) way to provide the JSON data to the JavaScript Web page besides the WebService?
-- Edit, remarks: ---
Needs to be application intrinsic. No web server can be installed, no extra run time can be used. The user just runs the app. Maybe the Qt WebKit could be an approach....
-- Edit 2 --
Currently checking the tiny web servers as of SO " Qt HTTP Server? "
As of my tests, currently I am using QtWebApp: http://stefanfrings.de/qtwebapp/index-en.html This is one of the answers of Edit 2 ( Qt HTTP Server? )
Stefan's small WebServer has some well documented code, is written in "Qt C++" and easy to use, especially if you have worked with servlets already. Since it can be easily integrated in my Qt project, I'll end up with an internal WebServer.
Some demo code from my JSON tests, showing that generating the JSON content is basically creating a QString.
void WebServiceController::service(HttpRequest& request, HttpResponse& response) {
// set some headers
response.setHeader("Content-Type", "application/json; charset=ISO-8859-1");
response.setCookie(HttpCookie("wsTest","CreateDummyPerson",600));
QString dp = WebServiceController::getDummyPerson();
QByteArray ba = dp.toLocal8Bit();
const char *baChar = ba.data();
response.write(ba);
}
If someone has easy examples with other libs to share, please let me know.
QByteArray ba = dp.toLocal8Bit();
const char *baChar = ba.data();
You don't need to convert the QByteArray to char array. Response.write() can also be called with a QByteArray.
By the way: qPrintable(dp) is a shortcut to convert from QString to char array.

How to retrieve data from CRM 2011 by using webservice and SSIS

Goal:
Retrieve data from Dynamics CRM 2011 to my database from SQL server R2 by using webservice through integration services (SSIS). Webservice needed to be located inside of SSIS. Gonna use the data for data warehouse.
Problem:
How do I do it?
We only write to Dynamics so I can't address the specific method name but the general idea below should get you started.
Assumptions
Two variables have been defined in your package and they are passed to the script component as ReadOnlyVariables: CrmOrganizationName, CrmWebServiceUrl.
A script component has been added to the dataflow as a Source component. On the Inputs and Outputs tab, an appropriate number of columns have been added to Output 0 (or whatever you define your output collection as) with appropriate data types.
Inside the script, add a web reference to your CRM instance. This code assumes it's called CrmSdk.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
// web reference
using CrmSdk;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
public override void CreateNewOutputRows()
{
// Get a reference to the CRM SDK
CrmSdk.CrmService CrmService = new CrmSdk.CrmService();
// An Authentication Token is required because CRM requires an OrganizationName
// to identify the Organization to be used
CrmSdk.CrmAuthenticationToken token = new CrmSdk.CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = this.Variables.CrmOrganizationName;
CrmService.CrmAuthenticationTokenValue = token;
// Use default credentials
CrmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Get the web service url from the config file
CrmService.Url = this.Variables.CrmWebServiceUrl;
//////////////////////////////////////////////////
// This code is approximate
// Use the appropriate service call to get retrieve
// data and then enumerate through it. For each
// row encountered, call the AddRow() method for
// your buffer and then populate fields. Be wary
// of NULLs
//////////////////////////////////////////////////
foreach (CrmSdk.entity person in CrmService.Get())
{
Output0Buffer.AddRow();
Output0Buffer.FirstName = person.FirstName;
Output0Buffer.LastName = person.LastName;
}
}
}
Caveats
There is no error handling, checks for nulls or anything elegant. The service should probably have been defined with the using statement, etc, etc, etc. It should provide an appropriate starting point for understanding how to consume a web service and load data into the pipeline.
The easiest solution for your requirement is to use a third-party library for SSIS. The commercial COZYROC SSIS+ library includes Dynamics CRM adapters, which support all deployment models: Premise, Live, Hosted, Federation, Office 365.