Real Software Forums
http://forums.realsoftware.com/

ODBC Datasource property is blank
http://forums.realsoftware.com/viewtopic.php?f=3&t=48053
Page 1 of 1

Author:  AfterTen [ Mon Jun 03, 2013 2:13 pm ]
Post subject:  ODBC Datasource property is blank

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?

Author:  eugenedakin [ Mon Jun 03, 2013 9:33 pm ]
Post subject:  Re: ODBC Datasource property is blank

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

Author:  AfterTen [ Mon Jun 03, 2013 9:47 pm ]
Post subject:  Re: ODBC Datasource property is blank

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.

Author:  eugenedakin [ Mon Jun 03, 2013 11:11 pm ]
Post subject:  Re: ODBC Datasource property is blank

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

Author:  AfterTen [ Tue Jun 04, 2013 6:43 am ]
Post subject:  Re: ODBC Datasource property is blank

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.

Author:  p0wn3d [ Tue Jun 04, 2013 7:00 am ]
Post subject:  Re: ODBC Datasource property is blank

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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/