Access sqlite from a remote server

2019-01-15 16:06发布

I am wondering how i can access an sqlite database that is sitting a remote server.I have read threads discouraging it but i need to do it if its possible.

     /*
QUrlOperator xc("http://example.com");
xc.get("testdatabase.db");
*/

QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );

  db.setDatabaseName(xc.get("testdatabase.db"));
  //idea

  if( !db.open() )
  {
    qDebug() << db.lastError();
    qFatal( "Failed to connect." );
  }

标签: qt sqlite3
7条回答
爷、活的狠高调
2楼-- · 2019-01-15 16:28

sqlite is a document database meaning that its pretty much just a flat file store of your data with only the most minimal database engine on top, that is why it is like 300kb total. What you can do as a solution is to copy the db from your remote location to your location via ftp or access it by assigning a network share location to it. Be warned though that only 1 user can write to sqlite at a time.

查看更多
何必那么认真
3楼-- · 2019-01-15 16:31

You could use php on the server to run whatever sql commands you need and just navigate to the php page from the device.

查看更多
霸刀☆藐视天下
4楼-- · 2019-01-15 16:32

Navicat can connect via SSH to a remote sqlite database.

For smaller project im using phpliteadmin

查看更多
该账号已被封号
5楼-- · 2019-01-15 16:32

You cannot directly access an sqlite database remotely like that. If you need to share it, you will have to develop a web service and talk to the web service rather than the database from your Qt Application.

There are some tools which act as a web service for stuff like that, e.g. this site has some links.

查看更多
虎瘦雄心在
6楼-- · 2019-01-15 16:40

SQLite is file-based only. There is no way to talk to it over TCP/IP.

Like an Access database file, you have to have the database file in a network shared folder. The path is usually going to be a UNC path, like "\server\sharename\folderpath\databasefile".

The problem is the connection string you built isn't a connection string. It's a partial string. You have this:

DataSource = @"\\\\" + txtipaddress.Text + @"\qscanDBAttacheds\test.s3db;Version=3;New=False;Compress=True;"

The "DataSource" part has to be part of the string you build. You don't have that. You need this:

string connString = @"Data Source=\\" + txtipaddress.Text + @"\qscanDBAttacheds\test.s3db;Version=3;New=False;Compress=True;"
查看更多
smile是对你的礼貌
7楼-- · 2019-01-15 16:44

SQLite isn't a network database, so it doesn't have any network connection ability built into it.

You would need to either:

  • Make the SQLite DB available on a network-accessible shared drive OR
  • Write/find an existing network server/web service for it

A web application is essentially a web service. If you happen to be running a web application on top of this DB, just expose certain levels of DB access to admins-only.

It's not recommended you do this because multiple threads/clients/etc. accessing a SQLite DB simultaneously may lead to concurrency problems very quickly.

查看更多
登录 后发表回答