Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Oct 17, 2017 12:41 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: ODBC Datasource property is blank
PostPosted: Mon Jun 03, 2013 2:13 pm 
Offline

Joined: Wed Oct 19, 2005 9:29 pm
Posts: 18
I want to do a simple thing.
Call db.Connect where db is a ODBCDatabase object
and call it with db.DataSource = ""

This brings up the dialog box so the user chooses an ODBC database.
What should happen at this point is that db.DataSource contains the connection string I need the next time the app runs.
So, I would save that string to my preferences so that I could connect to that database in the future.

Problem is that db.DataSource is blank upon the return from db.connect even though the connection was successful.

I'm running 2012r2.1 and the ODBC plugin that came with it.

Any ideas?


Top
 Profile  
Reply with quote  
 Post subject: Re: ODBC Datasource property is blank
PostPosted: Mon Jun 03, 2013 9:33 pm 
Offline

Joined: Mon Jan 02, 2006 11:43 am
Posts: 172
Location: Calgary, Alberta, Canada
Hello,

Once you create a .dsn file, the connection data is located in the file. To then reconnect using a .dsn file, then connect to the file with the DataSource command.

Here is database connection code to a .dsn file
//ODBC Connection to a Microsoft Access 2007 database
Dim db as ODBCDatabase

db = new ODBCDatabase

db.DataSource="filedsn=c:\user\test.dsn;DBQ=C:\UserMyContactList.mdb;User Id=admin;Password=;"

if db.Connect() then
MsgBox "Connected"
else
MsgBox "Connection failed: " + db.ErrorMessage
end if

db.Close


Here is what is in the .dsn file

[ODBC]
DRIVER=Microsoft Access Driver (*.mdb, *.accdb)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=2048
FIL=MS Access
DriverId=25
DefaultDir=C:\user
DBQ=C:\user\MyContactList.mdb


Happy to help, :)

Eugene
I Wish I Knew How To… Program Access 2010 with Real Studio Desktop Apps in Windows
Author Website: http://scispec.ca/Realbasic/Publish/Publish.htm
Vendor Website: http://great-white-software.com/rblibrary/index.php?main_page=index&manufacturers_id=34


Top
 Profile  
Reply with quote  
 Post subject: Re: ODBC Datasource property is blank
PostPosted: Mon Jun 03, 2013 9:47 pm 
Offline

Joined: Wed Oct 19, 2005 9:29 pm
Posts: 18
My program is used by end users. They setup a connection to a database using their ODBC client.
Then they run my program. In my program they choose to store their data using an ODBC connection.

Doing a DB.connect with the DB.DataSource string equal to "" makes a dialog box appear so the user can choose an ODBC connection they have set up themselves.
This dialog box is provided by RB, it is not one I invented.

Used to be that after the return from DB.connect the DB.DataSource property would no longer be blank it would have the connection string filled in. I would then store that string and use it as the DB.DataSource string the next time the program was run.

This seems to no longer work.

Here is my question. How are people handling ODBC connections for end-user programs. Not in-house, not personal when you know what the connection string is.
In my case, nothing is known about the ODBC connection the user is going to use.


Top
 Profile  
Reply with quote  
 Post subject: Re: ODBC Datasource property is blank
PostPosted: Mon Jun 03, 2013 11:11 pm 
Offline

Joined: Mon Jan 02, 2006 11:43 am
Posts: 172
Location: Calgary, Alberta, Canada
Hello,

I have a customer which uses something similar, with the exception that the connection is DSN-Less. When the user starts the program they are asked where the database file is located. This is where I remember the file name in a string and save it as a preference file. This preference file runs at the beginning of the program and loads the file without having to repeatedly ask the user where the file is located.

I didn't realize that the connection string was automatically filled in. This may be an update from Microsoft to minimize issues with hackers connecting to a database. This appears to be a Microsoft change, not a Real Studio change.

Does this help?

Eugene


Top
 Profile  
Reply with quote  
 Post subject: Re: ODBC Datasource property is blank
PostPosted: Tue Jun 04, 2013 6:43 am 
Offline

Joined: Wed Oct 19, 2005 9:29 pm
Posts: 18
Helps a little but won't get me to my ultimate solution.
My program collects data and stores it in a database. I want the user to be able to set up whatever DB they would like using ODBC.

The reason this question comes about is that my customer wants to store the data in a MSSQL DB.
There is no DB 'file' just a server and a database name. But the real point is that I have no real idea about their DB, it's just ODBC.
So, the first time they run the program the RB provided ODBC DSN chooser dialog comes up and they choose a DSN from their list.
But, now I don't seem to have any way to store what they have just chosen for future use.


Top
 Profile  
Reply with quote  
 Post subject: Re: ODBC Datasource property is blank
PostPosted: Tue Jun 04, 2013 7:00 am 
Offline
User avatar

Joined: Sun Oct 28, 2012 4:54 am
Posts: 264
Location: Herts, UK
I presume Windows OS.

Quote:
They setup a connection to a database using their ODBC client.


Why not just read and write to the registry.
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI

Just an idea.

_________________
Real Studio 2012 R2
SysInfo
BackTrack Linux/BackBox Linux/Debian Lenny/Windows 7/Windows 8/OpenWRT/OpenBSD
& Yes it's me in the Avatar


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group