Solved

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

Posted on 2014-02-10
9
527 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 43

Expert Comment

by:Rob
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 143

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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 43

Expert Comment

by:Rob
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 43

Expert Comment

by:Rob
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

738 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