Solved

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

Posted on 2014-02-10
9
506 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now