New topic: 

ODBC Datasource property is blank

<http://forums.realsoftware.com/viewtopic.php?t=48053>

         Page 1 of 1
   [ 6 posts ]             Print view    Previous topic | Next topic          
Author  Message        AfterTen          Post subject: ODBC Datasource property 
is blankPosted: Mon Jun 03, 2013 2:13 pm                         
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                eugenedakin          Post 
subject: Re: ODBC Datasource property is blankPosted: Mon Jun 03, 2013 9:33 pm  
                       
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                AfterTen          Post subject: 
Re: ODBC Datasource property is blankPosted: Mon Jun 03, 2013 9:47 pm           
              
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                eugenedakin          Post 
subject: Re: ODBC Datasource property is blankPosted: Mon Jun 03, 2013 11:11 pm 
                        
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                AfterTen          Post subject: 
Re: ODBC Datasource property is blankPosted: Tue Jun 04, 2013 6:43 am           
              
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                p0wn3d          Post subject: 
Re: ODBC Datasource property is blankPosted: Tue Jun 04, 2013 7:00 am           
                      
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             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 6 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to