Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ VBscript
➜ DSNless connection to a MySQL Database
DSNless connection to a MySQL Database
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| C
(10 posts) Bio
|
Date
| Sat 30 Aug 2003 04:43 PM (UTC) Amended on Sat 30 Aug 2003 04:44 PM (UTC) by C
|
Message
| Hey,
I have searched the net a bit looking for the connection string to connect without a DSN to a MySQL database. Anyone know what it might be? At the moment I am just using the following code:
Set objConn = CreateObject("ADODB.Connection")
strDSN = "DSN=dsnname;UID=;PWD="
objConn.Open strDSN
That works fine, but a DSNless connection is a little quicker and speed is important to me :)
Thanks for any help. | Top |
|
Posted by
| Shadowfyr
USA (1,790 posts) Bio
|
Date
| Reply #1 on Sat 30 Aug 2003 07:27 PM (UTC) Amended on Sat 30 Aug 2003 07:29 PM (UTC) by Shadowfyr
|
Message
| You probably can't from in a script. Scripts are inherently reliant on COM access methods, so you are forced to use slower access methods. You could build a COM program that uses a direct way to talk the the database, but then you would have to have the script calling the COM program and it would still be slow. Assuming Python has some sort of library for MySQL, then you could probably use it to directly access the database, but you would also lose some portability with other Mushclient users. This assumes though that there is even a library wrapper to support MySQL in Python.
I am almost 100% certain though that no more direct method exists for VBScript, JScript or PerlScript. They just where not designed to provide such a thing.
Hmm.. Here we are, though not sure how well it works so far:
http://sourceforge.net/projects/mysql-python/
---
If you can't find a fast or rational way to do something, you are probably using a Microsoft product. ;) | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #2 on Sun 31 Aug 2003 07:18 AM (UTC) |
Message
| Yes, you can do that. See this post:
http://www.gammon.com.au/forum/?bbsubject_id=1552
Here is an example:
sub AddRecordTable (first, last, phone, notes)
dim db
Set db = CreateObject ("ADODB.Connection")
' Open the connection
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\mushclient\mydb.mdb"
db.Execute "INSERT INTO Contacts (FirstName, LastName," & _
"Phone, Notes) VALUES (" & _
"""" & first & """, " & _
"""" & last & """, " & _
"""" & phone & """, " & _
"""" & notes & """ );"
db.Close
Set db = Nothing
end sub
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shadowfyr
USA (1,790 posts) Bio
|
Date
| Reply #3 on Sun 31 Aug 2003 06:22 PM (UTC) |
Message
| Ah hah.. This time I have got you Nick, unlike the prior post I responded to without looking for the date. He was asking if it was possible to access databases some way 'other' than DSN. ;) | Top |
|
Posted by
| Meerclar
USA (733 posts) Bio
|
Date
| Reply #4 on Sun 31 Aug 2003 07:58 PM (UTC) |
Message
| Sure it is, if he feels like writing a custom application for it. As far as accessing thru a script, DSN is pretty well the only viable option since scripting wasn't really designed to accomodate anything else. |
Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org | Top |
|
Posted by
| Shadowfyr
USA (1,790 posts) Bio
|
Date
| Reply #5 on Sun 31 Aug 2003 08:22 PM (UTC) |
Message
| Actually Meerclar, building a custom application wouldn't do anything for you. The reason DSN is slow is because it doesn't use direct library access to a database functions, but instead relies on COM. If you use your own app, then you are just shifting the COM support from the DSN server to one of your own, with the same resulting drop in speed. The alternative method of using Python may solve this, since the script itself would use a Python library to access the MySQL database. This 'should' be faster, but I can't be sure how much faster or even if it will work from inside Mushclient. All in all though, Python seems to be the best bet for doing anything that the MS Windows Scripting system, can't, won't or does do, but inefficiently. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sun 31 Aug 2003 09:11 PM (UTC) |
Message
| Muahahaha!
Unless I misunderstood the original post which said "looking for the connection string to connect without a DSN" I have done that.
The DSN (data source name) I took to be the thing you set up in the ODBC control panel. This is the relevant part of his original post:
DSN=dsnname
My response was to allow a connection by using the actual file name, that saves going through the DSN to file name mapping, and also avoids the user having to make a DSN entry into the ODBC control panel.
However until "C" responds we won't know if this is what he wanted or not. He didn't say he wanted another way than scripting. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| C
(10 posts) Bio
|
Date
| Reply #7 on Sun 31 Aug 2003 10:41 PM (UTC) |
Message
| Sorry to leave everyone hanging :p
Sorry Shadowfyr, Nick is indeed correct in his interpretation of what I am looking for. The code posted: sub AddRecordTable (first, last, phone, notes)
dim db
Set db = CreateObject ("ADODB.Connection")
' Open the connection
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\mushclient\mydb.mdb"
db.Execute "INSERT INTO Contacts (FirstName, LastName," & _
"Phone, Notes) VALUES (" & _
"""" & first & """, " & _
"""" & last & """, " & _
"""" & phone & """, " & _
"""" & notes & """ );"
db.Close
Set db = Nothing
end sub
This works fine for an access database, but my database is a MySQL database, so the Provider and Data Source would be different. I have seen this done for SQL Server [Although this is another MS product], so maybe it can't be done with MySQL and I will just have to make do with what I have.
Just had a look around there and according to a post on Experts exchange you can only access SQL Server, Jet and Oracle via DSNless connections.
[e.g. ConnStr = "driver={SQL SERVER};server=localhost;uid=user;pwd=pass;database=somedatabase" ]
Thanks anyway guys! :) | Top |
|
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Reply #8 on Sun 31 Aug 2003 11:39 PM (UTC) |
Message
| Forum wars? |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
Posted by
| Shadowfyr
USA (1,790 posts) Bio
|
Date
| Reply #9 on Mon 01 Sep 2003 12:17 AM (UTC) |
Message
| Ok.. I didn't realize there was a significant difference there. Oh well. lol | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
33,607 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top