1. Beatrix Willius
  2. as SQLite DB Server
  3. Tuesday, June 16 2020, 07:50 AM
  4.  Subscribe via email
Continuing the discussion from https://www.valentina-db.com/de/discussions/7458-transactions-committing-to-vsqlite .

I found my problem and - yes - I was totally stupid. Ahem, I had assumed that CreateDatabaseFileEx() simply opens a database if it already exists. But it makes a new database. However, I can't figure out how to open a database.


db.Host = "localhost"
db.UserName = "sa"
db.Password = "sa"
db.Port = 15532
Connected = db.Connect()

if Connected then
db.databaseName = "vsqlitetest.sqlite"
connected = db.OpenDataBaseFile
if not Connected then Connected = db.CreateDatabaseFileEx()
end if



If the database already exists then an OpenDataBaseFile doesn't open the database. In the attached screenshot you can see that isOpen = false.

How do I open a VSQLiteDatabase?
Attachments (1)
Comment
There are no comments made yet.
Beatrix Willius Accepted Answer
Thanks!
Comment
There are no comments made yet.
Ruslan Zasukhin Accepted Answer
V4RB Examples improved in 10.4.6
Comment
There are no comments made yet.
Beatrix Willius Accepted Answer
Thanks, guys! Got everything working now. Please update your example.
Comment
There are no comments made yet.
Ivan Smahin Accepted Answer

if( gClient ) then
db.Host = "localhost"
db.UserName = "sa"
db.Password = "sa"
db.Port = 15532 // optional. You can change port for SQLite DB connections in the VServer.ini file.

'
' Create or Open db:
'

'' Create:
'Connected = db.Connect()
'if Connected then
'// only NOW we specify db_name, and do create on remote Valentina SQLite Server. Must be ADMIN.
'db.databaseName = "vsqlitetest.sqlite"
'Connected = db.CreateDatabaseFileEx() // assign again into the same variable, will be TRUE if db was created under VServer, so we can use DB.
'end if

'' Open:
'db.DatabaseName = "vsqlitetest.sqlite"
'Connected = db.Connect()

' Create if not exists:
db.DatabaseName = "vsqlitetest.sqlite"
Connected = db.Connect()
if not Connected then
Connected = db.CreateDatabaseFileEx() // assign again into the same variable, will be TRUE if db was created under VServer, so we can use DB.
end if
...
Comment
There are no comments made yet.
Ivan Smahin Accepted Answer
Actually, OpenDataBaseFile() is an alias to Connect() for local dbs. It cannot be used with remote Valentina SQLite Server.
Comment
There are no comments made yet.
Ivan Smahin Accepted Answer
Please, check our example:

To always create the db you should do:

Connected = db.Connect()

if Connected then
// only NOW we specify db_name, and do create on remote Valentina SQLite Server. Must be ADMIN.
db.databaseName = "vsqlitetest.sqlite"
Connected = db.CreateDatabaseFileEx() // assign again into the same variable, will be TRUE if db was created under VServer, so we can use DB.
end if
...
// Db was created.
...


If you want to open db you should set db.databaseName property before db.Connect() call:


db.DatabaseName = "vsqlitetest.sqlite"
Connected = db.Connect()
...
// Db was opened.
...


In case if db can not be opened Connected will be false.
Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.

Categories

Announcements & News
  1. 0 subcategories
Valentina Studio
  1. 2 subcategories
Valentina Server
  1. 4 subcategories
Valentina Database ADK
  1. 0 subcategories
Valentina Reports ADK
  1. 0 subcategories
Other Discussions
  1. 2 subcategories
BETA Testing
  1. 0 subcategories
Education & Research
  1. 0 subcategories