Qt Connection to DB2 - qt

As a test I tried connecting to a DB2 server using the QODBC driver. I did this by creating a DSN and then providing the needed data such as hostname and the rest.
But what if I want to run my app in another computer. Is there another way to connect to a DB2 database, because as I see it this would also limit me if I tried to compile and run my program in iOS.

You can use QSqlDatabase class like this:
bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QDB2");
db.setHostName("mozart.konkordia.edu");
db.setDatabaseName("musicdb");
db.setUserName("gbatstone");
db.setPassword("T17aV44");
if (!db.open()) {
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
return false;
}
return true;
}
[EDITED]
How to Build the QDB2 Plugin on Windows
The DB2 header and include files should already be installed in the right directories. You just have to build the plugin as follows:
cd %QTDIR%\src\plugins\sqldrivers\db2
qmake "INCLUDEPATH+=<DB2 home>/sqllib/include" "LIBS+=<DB2 home>/sqllib/lib/db2cli.lib"
nmake

Related

How do I access a Sqlite3 database from an Electron AppImage .mount point?

OS: Linux 5.9.16-1-MANJARO
Electron version: 10.1.5
BetterSqlite version: 7.1.2
I am currently writing an application using Electron and BetterSqlite.
I build the AppImage like this:
npm run build && electron-builder build
This is how I access the database from my code:
db = new Database(
path.join(__dirname, `/${dbName}`).replace("/app.asar", "")
);
I have added the database file to use using:
"extraResources": [
"public/build/Database.db"
],
But when I open the AppImage i get the following error message:
SqliteError: attempt to write a readonly database
The database seems to be inaccessible due to the /tmp/.mountxxx point being readonly.
This behavior does not occur when I open the application in the development folder since it's not a readonly directory.
Is there a way to use the database from the /tmp/.mountxxx directory?
How would I got about accessing the database another way?
Thank you in advance.
I have searched for a way to use the AppImage mount point to read and write but I have not found anything. I will be using the user's home directory to store the database
As the error says when an AppImage is executed the AppDir is mounted as RO filesystem.
To workaround this you need to copy the database file into the user home using an startup script. By example you can copy it to "$HOME/.cache/com.myapp/appdata.db" then use this new copy.

Connect local ReactionCommerce app with remote database

How can I connect my local running reaction app with a remote mongodb?
I tried creating this settings.json file
{
"env" : {
"MONGO_URL" : "<remote db url >"
}
}
And ran the app with this command
meteor run --inspect-brk --settings settings.json
But it still connects to local meteor mongo. Could someone tell me the correct syntax to configure mongo.
Use a .env file at the root of your reaction directory, defining MONGO_URL (and any other environment variable you may need) this way:
MONGO_URL=<MongoDB URL>

Update-Database connects to wrong database

I set connection string in my Startup.cs (Startup class and ConfigureServices method). Sample code below:
if (_currentEnvironment.IsProduction())
{
connectionString = "ProdConnection string here ..";
}
else
{
connectionString = "Devl connection string here ...";
}
In the Package Manager Consoler of my Visual Studio 2017, when I do an Update-Database -Migration someMigration it always applies it to Devl database even when the environment is set to production.
How can I force it to connect to production?
The hosting environment uses environment variables to determine the current environment. In the package management console, be sure to set this environment variable before running the EF Core commands:
$env:ASPNETCORE_ENVIRONMENT="Production"

Grails and SQLite

Trying to get SQLite working with grails...stuff I've found on the web seems a little dated - references to ivy and plugins and such, but based on these:
http://stackoverflow.com/questions/1199512/grails-sqlite
http://bigohno.blogspot.com/2010/01/groovy-on-grails-sqlite.html
http://maven-repository.com/artifact/org.xerial/sqlite-jdbc/3.6.17
I've been able to get it working in a test environment...oddly, when I "prod war" my grails app and deploy to tomcat it fails with:
Dialect class not found: hibernate.SQLiteDialect
Here's my setup:
in conf/hibernate added a class for the SQLiteDialect. This .java was taken from here http://code.google.com/p/hibernate-sqlite/
Then in my DataSource.groovy I have:
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
// SQLite
// !!!see also BuildConfig for Dependancies!!!
dbCreate="update"
url='jdbc:sqlite:C:\\sqlite-shell-win32-x86-3080100\\rss_1.db'
logSql="true"
dialect="hibernate.SQLiteDialect"
driverClassName="org.sqlite.JDBC"
readOnly="true"
}
}
production {
dataSource {
// SQLite
dbCreate="update"
url="jdbc:sqlite:/opt/sqlite/dbs/rss/1/rss_1.db"
logSql="true"
dialect="hibernate.SQLiteDialect"
driverClassName="org.sqlite.JDBC"
readOnly="true"
showsql="false"
}
}
}
and in BuildConfig.groovy I have:
dependencies {
runtime 'org.xerial:sqlite-jdbc:3.6.17'
}
I also jar'd up the .java dialect class and put in in lib - some posts said this helped. I also put sqlite-jdbc-3.7.15-M1.jar in lib.
Now when I run-app in my dev environment it runs fine...but when I deploy to tomcat I get the dialect error.
Is there something special I need to do to the prod environment for the dialect?
Here's how to setup SQLite with Grails:
Download SQLite from http://www.sqlite.org/download.html , extract and save to a directory. You may also want to create directories for your databases.
Download SQLite JDBC jar from https://bitbucket.org/xerial/sqlite-jdbc and put the jar in your grails lib directory.
Download a SQLIte dialect...google search as there are many, but you may reference https://github.com/gwenn/sqlite-dialect or https://gist.github.com/virasak/54436
In grails, create a class in src/java and put your dialect code in.
I also jar'd this class up and put the jar in lib.
Setup your grails datasource, e.g.,:
dataSource {
// SQLite
dbCreate="update"
url="jdbc:sqlite:/opt/sqlite/dbs/rss/1/rss_1.db"
logSql="true"
dialect="SQLiteDialect"
driverClassName="org.sqlite.JDBC"
}
NOTE: Depending on whether your sqlite dialect class is in a package, you may need to prefix the package name to the dialect above (mine was not).
In BuildConfig.groovy, add a dependency to sqlite jdbc, like so:
dependencies {
runtime 'org.xerial:sqlite-jdbc:3.6.17'
}
That's what worked for me!

How to capture IIS Express output when run from Visual Studio 2010 SP1?

If you run IIS Express from the command line, anything you write Console.Out in your web app is displayed in the command line output. This is very handy for trouble shooting LINQ to SQL translation issues if you set DataContext.Log = Console.Out. However, if you check "Use IIS Express" in the web project properties in VS 2010 SP1 you never see the command line.
Can you redirect IIS Express Console.Out to a log file or something?
I found a way to write directly to the Debug Console window via damieng's blog:
class DebugTextWriter : System.IO.TextWriter {
public override void Write(char[] buffer, int index, int count) {
System.Diagnostics.Debug.Write(new String(buffer, index, count));
}
public override void Write(string value) {
System.Diagnostics.Debug.Write(value);
}
public override Encoding Encoding {
get { return System.Text.Encoding.Default; }
}
}
You can attach it to a DataContext like you would with Console.Out:
#if DEBUG
db.Log = new DebugTextWriter();
#endif
http://damieng.com/blog/2008/07/30/linq-to-sql-log-to-debug-window-file-memory-or-multiple-writers
You can see console output, if you setup 'image file execution option' for iisexpress.exe. Only issue is, you will see a popup console window when a new iisexpress.exe is started. You can setup this only when you want to see console traces.
Do following to setup image file execution option:
install windbg from http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx
Setup following registry key (This link may help you http://msdn.microsoft.com/en-us/library/a329t4ed(VS.71).aspx)
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\iisexpress.exe]
"Debugger"="c:\\windbg -g -G"
You can disable image file execution option by renaming or deleting above registry key.

Resources