|
umdbandit Wanderer
Joined: 31 Oct 2004 Posts: 94
|
Posted: Sat Apr 28, 2007 8:37 pm
External Databases |
Is there a way to be connected to an external database, and run queries/commands on it from within cmud?
|
|
_________________ Rufus- Winner of Stuff |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Sat Apr 28, 2007 11:46 pm |
You can use %comcreate and ADOB.Connection object, Try searching this site for %comcreate database.
Have a look at this thread.
Check out the msdn page on using the ADOB.Connection object.
If you're stuck after that post back giving an idea of which database base you want to connect to and maybe an idea of what you want to do with it.
I'm sure we can help you get started. |
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
umdbandit Wanderer
Joined: 31 Oct 2004 Posts: 94
|
Posted: Tue May 08, 2007 3:55 am |
I installed mysql 5
so first I do
#VAR Conn %comcreate( "ADODB.Connection")
then i do
#call @conn.open("test")
which gets this error:
Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
not really sure where to go from here |
|
_________________ Rufus- Winner of Stuff |
|
|
|
bortaS Magician
Joined: 10 Oct 2000 Posts: 320 Location: Springville, UT
|
Posted: Tue May 08, 2007 7:29 am |
You forgot to add a connection string. The connection string is what tells ADO where to find the database, and credentials if it needs any. This page has the various connection strings that you could use:
http://www.connectionstrings.com/?carrier=mysql
ADO also needs a database provider. My experience has been that OleDB providers behave better than ODBC. Your mileage may vary. Go to the MySQL website and look at the Connector downloads. Download and install the ODBC driver if you don't want to mess with .NET stuff. The page for the connectors is here:
http://dev.mysql.com/downloads/connector/ |
|
_________________ bortaS
~~ Crusty Klingon Programmer ~~ |
|
|
|
umdbandit Wanderer
Joined: 31 Oct 2004 Posts: 94
|
Posted: Tue May 08, 2007 6:54 pm |
Ok, so now I have
#VAR connstr "Driver={MySQL ODBC 3.51 Driver};Server=127.0.0.1;Port=3306;Database=t2t;User=root;Password=nautica;Option=3"
#VAR Conn %comcreate( "ADODB.Connection")
#call %comset(conn,"ActiveConnection",@connStr)
#call @conn.open("test")
.. same error.
Sorry for the constant messages :P Just want to get this right :) |
|
_________________ Rufus- Winner of Stuff |
|
|
|
bortaS Magician
Joined: 10 Oct 2000 Posts: 320 Location: Springville, UT
|
Posted: Tue May 08, 2007 9:34 pm |
No problem.
Try removing "test" from:
#call @conn.open("test")
So that it looks like:
#call @conn.open()
I've never had to use a parameter to open the connection to the database if I provided the info before hand. It's been a while since I've used ADODB. All of my database programming is on .NET nowadays.
After some Googling...
Use ConnectionString property instead of ActiveConnection. |
|
_________________ bortaS
~~ Crusty Klingon Programmer ~~ |
|
|
|
bortaS Magician
Joined: 10 Oct 2000 Posts: 320 Location: Springville, UT
|
Posted: Tue May 08, 2007 9:37 pm |
Also don't forget to always close your connection to the database:
#call @conn.Close()
after you get done playing with the database. Open connections to databases do weird things with your code. This is common source for memory leaks. |
|
_________________ bortaS
~~ Crusty Klingon Programmer ~~ |
|
|
|
|
|