Page 1 of 1
Database open with a Connection String
Posted: Thu Jul 15, 2004 7:54 pm
by Schobaer
Hi,
it would be nice if PB could open a Database with a ConnectionString like this:
OpenDatabase(0,"Driver=MySQL ODBC 3.51 Driver;Server=192.168.0.1;Host=localhost;Network=DBMSSOCN;Database=Cars;User=root;Password=","","")
So you only need to install the ODBC-Driver but not specify the connection.
Re: Database open with a Connection String
Posted: Mon Jun 21, 2010 3:11 pm
by endo
We still can't use dsn-less connection, right? I know there are some tricks on the forum.
It would be really nice if we could give connection string instead of dsn name.
Re: Database open with a Connection String
Posted: Tue Jun 22, 2010 6:49 pm
by Flype
Yes - it's a good idea.
This could offers much more control on the connection.
For those who don't knows (very handy) :
http://www.connectionstrings.com/
Re: Database open with a Connection String
Posted: Mon Oct 25, 2010 7:18 pm
by MarcNL
I'm totally new to Purebasic.
As no-one posted an answer I suppose this isn't possible?
I personally only need to specificy the databasename on an existing DSN, so f.e.:
Code: Select all
"DSN=<dsn_name>;DB=<database_name>;UID=<user>;PWD=<password>"
Other programming tools can do this easily, so this must/should be possible in Purebasic?
Re: Database open with a Connection String
Posted: Tue Oct 26, 2010 8:13 am
by endo
Hi, unfortunately DSN-less conntection is still not possible in Purebasic. There are some workarounds like creating/deleting a DSN programatically using odbcconf.exe which is the easiest way (on Windows)
Or use a dsn to connect to your database server and change the db using USE <dbname>.
Re: Database open with a Connection String
Posted: Tue Oct 26, 2010 10:58 am
by MarcNL
endo wrote:Hi, unfortunately DSN-less conntection is still not possible in Purebasic. There are some workarounds like creating/deleting a DSN programatically using odbcconf.exe which is the easiest way (on Windows)
Or use a dsn to connect to your database server and change the db using USE <dbname>.
Creating a separate DSN for each databasename isn't an option, as the number of databasenames can be long and dynamic. I hope that this feature will be introduced soon then, as this makes it difficult/cumbersome to create serious business applications with PureBasic ....
Re: Database open with a Connection String
Posted: Tue Oct 26, 2010 11:19 am
by endo
Yes I definitely agree with you.
My way is just a workaround. But it is not necessary to create DSN for each db, you can create one when your application starts (by calling the odbcconf.exe dos command) and delete when your app quits. Or just create it once when your application installed, then update it for different databases when it starts and remove it during uninstall.
Re: Database open with a Connection String
Posted: Tue Oct 26, 2010 3:28 pm
by MarcNL
endo wrote:Yes I definitely agree with you.
My way is just a workaround. But it is not necessary to create DSN for each db, you can create one when your application starts (by calling the odbcconf.exe dos command) and delete when your app quits. Or just create it once when your application installed, then update it for different databases when it starts and remove it during uninstall.
That could work, but unfortunately this is what Microsoft tells me:
ODBCCONF.exe will be removed in a future version of Windows Data Access Components. Avoid using this feature, and plan to modify applications that currently use this feature.
http://msdn.microsoft.com/en-us/library ... S.85).aspx
My strategy is not to use components that are or will be deprecated.
Re: Database open with a Connection String
Posted: Tue Oct 26, 2010 3:59 pm
by gnozal
You can create / delete ODBC DSN on the fly without any external tool.
An example :
http://www.purebasic.fr/english/viewtop ... 12&t=16474
Re: Database open with a Connection String
Posted: Tue Oct 26, 2010 4:03 pm
by MarcNL
Nicely done!
However I prefer not to use work-arounds like that (modifying registry fe); I still hope that Fred will just add an extra databasename argument to the OpenDatabase function. If he's that smart as many are telling then that should be done in 1 minute ....

Re: Database open with a Connection String
Posted: Tue Nov 16, 2010 6:52 pm
by Schobaer
Hi,
I think, this is the best method to use DSN.
In this case I had an additional Idee you can see here
http://www.purebasic.fr/english/viewtop ... =3&t=41182
EDIT: It is not the best way, but you can connect to the most Databases. Ok, Oracel and so on...
Re: Database open with a Connection String
Posted: Mon Nov 29, 2010 10:08 pm
by DoubleDutch
Flype wrote:Yes - it's a good idea.
This could offers much more control on the connection.
For those who don't knows (very handy) :
http://www.connectionstrings.com/
Thanks for the link, it is VERY handy!
