[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  DSNless connection to a MySQL Database
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

DSNless connection to a MySQL Database

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by C   (10 posts)  [Biography] bio
Date Sat 30 Aug 2003 04:43 PM (UTC)  quote  ]

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.
[Go to top] top

Posted by Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Reply #1 on Sat 30 Aug 2003 07:27 PM (UTC)  quote  ]

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. ;)

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Nick Gammon   Australia  (19,500 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 31 Aug 2003 07:18 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Reply #3 on Sun 31 Aug 2003 06:22 PM (UTC)  quote  ]
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. ;)

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Meerclar   USA  (590 posts)  [Biography] bio
Date Reply #4 on Sun 31 Aug 2003 07:58 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Reply #5 on Sun 31 Aug 2003 08:22 PM (UTC)  quote  ]
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.

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] top

Posted by Nick Gammon   Australia  (19,500 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Sun 31 Aug 2003 09:11 PM (UTC)  quote  ]
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
[Go to top] top

Posted by C   (10 posts)  [Biography] bio
Date Reply #7 on Sun 31 Aug 2003 10:41 PM (UTC)  quote  ]
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! :)
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #8 on Sun 31 Aug 2003 11:39 PM (UTC)  quote  ]
Message
Forum wars?

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Shadowfyr   USA  (1,776 posts)  [Biography] bio
Date Reply #9 on Mon 01 Sep 2003 12:17 AM (UTC)  quote  ]
Message
Ok.. I didn't realize there was a significant difference there. Oh well. lol

main {
__if (Schrodinger_Cat is Alive or version >= "XP"){
____if version = "Vista" then Performance /= Number_of_Cores;
____call Functional_Code();}
__else
____call Crash_Windows();}
[Go to top] 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.


10,752 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]