Solved

VB6 - cannot create a mysql db with a name having an underscore in it

Posted on 2014-02-10
9
513 Views
Last Modified: 2014-02-13
i can create a new mysql db manually with an name having an underscore in it but cannot create it programatically .. see below with the code

   Set cnnado = New adodb.Connection
   strCon = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=192.168.1.64;"
   strCon = strCon & "DATABASE=mysql; UID=xxxx;PWD=yyyyy;OPTION=3"
   cnnado.ConnectionString = strCon
   cnnado.Open
   strExecute = "CREATE DATABASE " & "aaaa_1"
   cnnado.Execute strExecute

This code works fine for a db name 'aaaa1' but nout for 'aaaa_1' .. i can create the db manually ok eg via the command prompt and mysql or using something like sqlyog.
0
Comment
Question by:jnoely
9 Comments
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39852265
The underscore is a special character so to use it you've got to escape it or user the chr(242)
E.g.
strExecute = "CREATE DATABASE " & "aaaa" & chr(242) & "1"
0
 
LVL 45

Expert Comment

by:aikimark
ID: 39852503
does it work if the database is enclosed in square brackets?
Example:
strExecute = "CREATE DATABASE " & "[aaaa_1]"

Open in new window

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39852535
I don't see why it would not accept the underscore:
http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

anyhow, for MySQL that would be backticks:
strExecute = "CREATE DATABASE " & "`aaaa_1`"
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39852545
To clarify my comment above, I'm referring to vb syntax where the underscore is used for continuation of code on new lines and may be being interpreted incorrectly in this case
0
 

Author Comment

by:jnoely
ID: 39855918
It does work with the 3.51  if you uses the back ticks !!! whopee
0
 

Author Comment

by:jnoely
ID: 39855920
many thanks
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39855930
Are you sure you allocated the points right here?
If the back ticks solved your issue then the points should go to angeliii along with an A grade
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question