How to interact with database file by c++ - c++

I am new to database programming.
I am trying to make an application that interacts with a database file locally so that I can use those database query.
I tried to use mySQL connection c++ 1.1.6, and run this example.
Following error is what I get:
MySQL server on '127.0.0.1' <10061> <MySQL error code: 2003, SQLState:>
I guess that I need to have a server on for connecting. What I want is just an interaction with a database file locally, do I need to make this connection also? If I really need this connection, how to make it works?

Related

How to Use CDatabase to connect to SQL Server database with ODBC?

My program uses ADO to connect to SQL Server in Visual C++ 2008. Now it seems that ADO is out-dated and MS recommends to use ODBC again.
Therefore, I now study how to use ODBC to connect to SQL Server. I see there is a class CDatabase that can do that. However, there are no good article in introducing how to use CDatabase to connect to SQL Server via ODBC.
Basd on my research, it seems one can connect to SQL Server via ODBC in the following way:
Via a direct connection string like this one:
Driver={SQL Server Native Client 11.0};Server=myServerAddress;
Database=myDataBase;Uid=myUsername;Pwd=myPassword;
Using ODBC administrator to create a DSN(Data Source Name), and then connect with DSN.
THen if 1 works, why do we need to create DSN?
You don't need a ODBC DSN. A DSN simply allows one to externalize the ODBC configuration such that server name, driver. etc. can be configured in a common way for all ODBC applications.
It is not a requirement to use a DSN when you store connection string in an external file so that environment-specific values can be configured without code changes. Regardless of the technique used, be sure to protect secrets rather than storing as clear text.

How to make a remote Sql Server connection in c++?

I developed an application that accesses the database locally.
Now, how to make this application access the database on another computer in the same network?
This is my connection:
db=QSqlDatabase::addDatabase("QODBC");
db.setDatabaseName("DRIVER={SQL SERVER};SERVER=XXXXXXXX-PC\\SQLEXPRESS;DATABASE=XXXXX;uid=sa;pwd=XXXX;Trusted_Connection=Yes");

Error : Can't connect to Mysql server on '' (10055)

Some times my appplication gives the following error. I do not understrand why this error occures .
My server database on windows machine. My server works perfectly with INSERT, UPDATE, DELETE for mysql.
After process~29000 files my application crash!
the relation between code and DB is based on a connections whose using ports on both sides client/server
that's why is totally recommended to close the connections after using it, because the exceed of opened port will block the connection wich will be the cause of launching such exception

Embedded database for desktop applications question

I want to make an application 'x' with an embedded database.If i make another application 'y' without an embedded database,will it be possible to read and update the database in application 'x'.
I'm not sure what you mean by "embedded" database mysql. Your application will connect to mysql via socket and any other application will connect to it (assuming it has right credentials). Alternatively you could use sqlite which is easier to manage in a desktop app environment.
Consider the needs of the solution. If you need to share the data, create a shared database. If you need to share business logic, create an application that services requests from that database. I'm am not sure what MySQL's capabilities are regarding embedding a database inside the application, but if you're embedding the database in an application, the data should stay inside the application.
No, I don't think so. Because you are using an embedded database it's actually part of your application (embedded) so it doesn't have any external interface as such. That's because embedded MySQL doesn't run a database server process to listen to requests. The database access logic is all linked into your application.
You could either:
Have application X listen on a port and forward requests to it's embedded DB, this at least abstracts away from the fact that it is DB in the background, it would look juist like any other service.
Use a non embedded DB, this should be pretty simple to setup really. You could have X start and stop the DB server when it starts and stops.
Use a file based database like SQLLite.

Connect to SQLite using ODBC without register database

Is it possible to connect to SQLite in C++ and using ODBC API without register the database in ODBC?
I have code that uses ODBC talking to databases and don't want to rewrite for using SQLite and don’t want to register new ODBC connections.
you should be able to do it without any code changes using sqliteodbc.
Short answer, use one of the following connection strings:
Driver=SQLite ODBC Driver;Database=full-path-to-db;...
Driver=SQLite3 ODBC Driver;Database=full-path-to-db;...
Long answer: The readme file included with the sqliteodbc driver covers the methods for connecting, using a DSN-less connection string.
See http://www.ch-werner.de/sqliteodbc/html/index.html