Adding SQL statements to ADODB connections

127 Views Asked by At

I am trying to pull some data from a mysql server and was using the GROUP_CONCAT function to compute the percentiles for a certain variable. I would like to increase the length of the group_concat_max_len to my sql query, when I use my data explorer, it is a simple statement of adding SET @@session.group_concat_max_len = 1000000; before my query. I am unsure about how to do this. I tried

connectionText = "Driver={MySQL ODBC 3.51 Driver};Server=" & Server_Name     & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"
Dim cnn As New ADODB.Connection
cnn.Open connectionText
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
cmd.CommandText = "SET  @@session.group_concat_max_len = 1000000;"
cmd.ActiveConnection = cnn

Set rs = New ADODB.Recordset 
rs.Open sqlquery, cnn, adOpenForwardOnly,adLockReadOnly, adCmdText

But this is not applying the setting I need. TIA.

1

There are 1 best solutions below

0
On BEST ANSWER

Figured out that I was trying to execute a command to the connection and not the database. It was fixed using

CommandText = "SET  @@session.group_concat_max_len = 1000000;"
cnn.Open connectionText
cnn.Execute (CommandText)