New topic: 

Open Two ODBC Databases Simultaneously Error

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

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        eugenedakin          Post subject: Open Two ODBC Databases 
Simultaneously ErrorPosted: Thu Oct 11, 2012 10:21 pm                         
Joined: Mon Jan 02, 2006 11:43 am
Posts: 129
Location: Calgary, Alberta, Canada                Hello Everyone, 

I am running Windows 7, Real Studio 2012 r1.1 and would like to open two 
databases and copy fields from one database to another. This is with a DSNless 
connection. Unfortunately an error occurs when opening the second database:

Quote:DBCopy Connection Failed:, Error Code: 0 
Then the following error occurs:
Quote:Real Studio.Exe has stopped working. A problem caused the program to stop 
working correctly. Windows will close the program and notify you if a solution 
is available.

Here is the code:
Dim i as integer
//Connecting to the first Database
Dim db as ODBCDatabase
Dim rs as RecordSet
db = new ODBCDatabase
db.DataSource = "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; 
DBQ=C:\User\Finding.accdb;User Id=admin;Password=;"

if db.Connect() then //Was the connection successful?
  'MsgBox "Connected"
else
  MsgBox "Finding DB Connection failed: " + db.ErrorMessage + ",Error Code: " + 
CStr(db.ErrorCode)
  return
end if

//Connecting to the second Database
Dim db1 as ODBCDatabase
Dim rs1 as RecordSet
db1 = new ODBCDatabase
db1.DataSource = "DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; 
DBQ=C:\User\DBCopy.accdb;User Id=admin;Password=;"

if db1.Connect() then //Was the connection successful?
  'MsgBox "Connected"
else
  MsgBox "DBCopy Connection failed: " + db1.ErrorMessage + ", Error Code: " + 
cstr(db1.ErrorCode)
  return
end if

//Get the data from the database
rs = db.SQLSelect("SELECT * FROM Widgets'") //Find data from Widgets

if rs <> Nil then //Continue if there is data
  do until rs.EOF //continue until we reach the End Of File
  db1.SQLExecute("INSERT INTO Widgets (Units, Description) VALUES 
('"+cstr(rs.Field("Units").Value)+"', '"+rs.Field("Description").Value+"')")
  rs.MoveNext //move to the next recordset
  loop //get the next row of data
else
  MsgBox "No RecordSet exists."
  Return
end if
rs.Close 'Close the first DB RecordSet
db.Close 'Close the first Database

db1.Close 'Close the second Database


I can create a lengthy workaround which opens the data into an array, close the 
first database, and then place the array information into the second database. 
I would prefer opening two databases simultaneously, as this becomes 
complicated with more than two databases open with multiple arrays.

Here is the link to download this example project and the example databases: 
http://www.mediafire.com/?vt089773z1gaxr7

Does anyone have some helpful suggestions?

Sincerely,

Eugene   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
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