Database open with a Connection String

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Schobaer
User
User
Posts: 16
Joined: Sat Mar 06, 2004 9:36 am
Location: Germany

Database open with a Connection String

Post 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.
endo
Enthusiast
Enthusiast
Posts: 141
Joined: Fri Apr 30, 2004 10:44 pm
Location: Turkiye (istanbul)
Contact:

Re: Database open with a Connection String

Post 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.
-= endo (registered user of purebasic since 98) =-
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Re: Database open with a Connection String

Post 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/
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
MarcNL
User
User
Posts: 34
Joined: Mon Oct 25, 2010 4:04 pm

Re: Database open with a Connection String

Post 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?
endo
Enthusiast
Enthusiast
Posts: 141
Joined: Fri Apr 30, 2004 10:44 pm
Location: Turkiye (istanbul)
Contact:

Re: Database open with a Connection String

Post 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>.
-= endo (registered user of purebasic since 98) =-
MarcNL
User
User
Posts: 34
Joined: Mon Oct 25, 2010 4:04 pm

Re: Database open with a Connection String

Post 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 ....
endo
Enthusiast
Enthusiast
Posts: 141
Joined: Fri Apr 30, 2004 10:44 pm
Location: Turkiye (istanbul)
Contact:

Re: Database open with a Connection String

Post 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.
-= endo (registered user of purebasic since 98) =-
MarcNL
User
User
Posts: 34
Joined: Mon Oct 25, 2010 4:04 pm

Re: Database open with a Connection String

Post 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.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: Database open with a Connection String

Post 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
MarcNL
User
User
Posts: 34
Joined: Mon Oct 25, 2010 4:04 pm

Re: Database open with a Connection String

Post by MarcNL »

gnozal wrote:You can create / delete ODBC DSN on the fly without any external tool.
An example : http://www.purebasic.fr/english/viewtop ... 12&t=16474
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 .... ;)
Schobaer
User
User
Posts: 16
Joined: Sat Mar 06, 2004 9:36 am
Location: Germany

Re: Database open with a Connection String

Post 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...
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Database open with a Connection String

Post 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! :)
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply