SQLite Remote Connection

Source: Internet
Author: User

SQLite Remote connection data

1. Connect to local Database

Qsqldatabase db =qsqldatabase::adddatabase ("Qsqlite");

Db.setdatabasename ("personnel.db");

Db.setusername ("Persionsql");//database user name and password

Db.setpassword ("123456");

if (!db.open ()) {

Qmessagebox::warning (0,qobject::tr ("Database Error"),

Db.lasterror (). text ());

return false;

}

Open the database under the current directory, or create a database named Personnel.db if it is not.

2, SQLite connect the local shared database

Qsqldatabase db = Qsqldatabase::adddatabase ("Qsqlite");

Db.sethostname ("localhost");//Set your local server's IP

Db.setdatabasename ("/sqllitedb/personnel.db");//Sqllitedb The name of the database under the shared directory

Db.setusername ("Persionsql");//database user name and password

Db.setpassword ("123456");

if (!db.open ())

Qdebug () << "Failed to connect to Qsqlite";

Else

Qdebug () << "success!";

Open the shared database under your native Sqllitedb directory, and if not, the open fails.

If you have the database in the shared directory, the Open is successful.

3, SQLite connection network sharing database

Qsqldatabase db =qsqldatabase::adddatabase ("Qsqlite");

Db.sethostname ("192.168.1.160");//Set the IP of your Web server

Db.setdatabasename ("/share/personnel.db");//share the name of the database under the shared directory

Db.setusername ("Persionsql");//database user name and password

Db.setpassword ("123456");

if (!db.open ())

Qdebug () << "Failed to connect to Qsqlite";

Else

Qdebug () << "success!";

Open the shared database under your network shared directory share, and if not, the open fails.

If you have the database in the shared directory, the Open is successful.

Note: Access to the network remote database must shut down the firewall on both the local and remote PC, the path of the remote database to be accessed cannot be a Chinese path, and the shared directory must have readable writable permissions.

SQLite Remote Connection

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.