Using CDatabase to open a ACCDB file is displaying a Select Database Source window - ms-access

I have a CDatabase.
One of my users has Access 2021 x64 installed. He runs the 64 bit edition of my software.
It opens a database like this:
CString strDBConnectString = L"Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=<path to db>;Pwd=";
m_Database.OpenEx(strDBConnectString, CDatabase::noOdbcDialog)
It refused to work on his PC and shows:
Why is it showing this? My development PC has Office 365 x64 and the same code works fine.
So what underlying issue is forcing this window to display?
Are you sure that the required driver you ask for is installed under this name?
Yes, I am. This is because I do not use a literal text value here but I detect it by examining the JET drivers list:
// We now iterate the JET drivers list and locate a valid MDB driver
CString CCommunityTalksApp::GetJETDriverEx(bool bAccDbMode)
{
CString strDriver;
CString strName, strNameLower, strValue;
CString strDefaultDriver = _T("Microsoft Access Driver (*.mdb)");
CString strDBType = _T("(*.mdb)");
CStringArray aryStrDrivers;
TCHAR szBuf[2001]{};
WORD cbBufMax = 2000;
WORD cbBufOut;
TCHAR* pszBuf = szBuf;
if (SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
{
#ifdef _WIN64
strDefaultDriver = _T("Microsoft Access Driver (*.mdb, *.accdb)");
strDBType = _T("(*.mdb, *.accdb)");
#else
if (bAccDbMode)
{
strDefaultDriver = _T("Microsoft Access Driver (*.mdb, *.accdb)");
strDBType = _T("(*.mdb, *.accdb)");
}
#endif
while (*pszBuf)
{
strName = CString(pszBuf);
strNameLower = strName;
strNameLower.MakeLower();
if (strNameLower.Find(strDBType) != -1)
{
aryStrDrivers.Add(strName);
if (strName.CollateNoCase(strDefaultDriver) == 0)
{
strDriver = strName;
break;
}
}
pszBuf += strName.GetLength() + 1;
}
if (strDriver.IsEmpty() && aryStrDrivers.GetSize() > 0)
{
// Try and use the first MDB driver we found
strDriver = aryStrDrivers.GetAt(0);
}
}
// Make a note of the driver
AfxGetApp()->WriteProfileString(_T("Options"), _T("JET Connection Driver"), strDriver);
return strDriver;
}

Related

Flash policy request C++

I am writing a socket server which has a Flash client. However, I can't get past the flash policy request.
My code:
if (buf[0] == 60) {
printf("Policy request spotted");
const auto& policy = Server::policy();
send(client, &policy, policy.size() + 1, 0);
close(client);
break;
}
std::string Server::policy(){
char c = 0;
return "<?xml version=\"1.0\"?>\r\n<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\r\n<cross-domain-policy>\r\n<allow-access-from domain=\"*\" to-ports=\"1-31111\" />\r\n</cross-domain-policy>" + c;
}
Doensn't seems to work. What do I need to do to fix it?
Thanks.
I got it fixed by using this:
char policy[] = "<?xml version=\"1.0\"?>\r\n<!DOCTYPE cross-domain-policy SYSTEM \"/xml/dtds/cross-domain-policy.dtd\">\r\n<cross-domain-policy>\r\n<allow-access-from domain=\"*\" to-ports=\"1-31111\" />\r\n</cross-domain-policy>\0";
send(client, &policy, sizeof(policy), 0);
in the if (buf[0] == 60) { statement.

[Qt][QMYSQL] Deployed app - Driver not loaded

First of all, many thanks for those who will take time to help me on this topic. I've searched a lot on many different forums before posting here but it seems I'm missing something.
Well, I'm working on Windows 7 (64 bits) with Qt5.5 / MySQL Server 5.6.
And I use MinGW 5.5.0 32 bits on Qt Creator (auto detected).
It's not a matter of building the drivers, it's done and it works perfectly for the dev.! :-)
I can reach my BD, do any query that I want and retrieve/insert all the data.
I'm facing to a matter of deploying my application on other computers.
I know that I have to put qsqlmysql.dll in a folder "sqldrivers" placed in my app. directory. Such as placing libmysql.dll in this directory too.
So I have something like the following
App directory
App.exe
libmysql.dll
Qt5Core.dll
Qt5Gui
Qt5Sql
Qt5Widget
libwinpthread-1.dll
libstdc++-6.dll
libgcc_s_dw2-1.dll
platforms
qwindow.dll
sqldrivers
qsqlmysql.dll
BUT when I release the application and I try to run it from another computer which I used to develop, I have a "Driver not loaded" error...
As far now, I have really no idea what I've missed...
So please, if anyone could give me some, it would be really really appreciated!
I let you the part of the code which is really useful, just in case...
main.cpp
QApplication a(argc, argv);
Maintenance w;
w.show();
return a.exec();
Maintenance.cpp
void Maintenance::login(){
int db_select = 1;
this->maint_db = Database(db_select);
/* All that follow is linked to the login of user... */
}
Database.cpp
Database::Database(int default_db)
{
this->db = QSqlDatabase::addDatabase("QMYSQL");
switch(default_db){
case 0:
this->db.setHostName("XXX.XX.XXX.XX");
this->db.setDatabaseName("maintenance_db");
this->db.setUserName("USERNAME");
this->db.setPassword("PASSWORD");
this->db.setPort(3306);
break;
// Only to make some trials in local
case 1:
this->db.setHostName("127.0.0.1");
this->db.setDatabaseName("maintenance_db");
this->db.setUserName("USERNAME");
this->db.setPassword("PASSWORD");
break;
}
/* I've added the following code to try to solve the problem
I retrieve that the available drivers are: QMYSQL / QMYSQL3
But all the information about the DB are empty (due to the unloaded driver I assume.)
And the error from *lastError()* is "Driver not loaded"
*/
QString my_drivers;
for(int i = 0; i < QSqlDatabase::drivers().length(); i++){
my_drivers = my_drivers + " / " + QSqlDatabase::drivers().at(i);
}
QString lib_path;
for(int i = 0; i < QApplication::libraryPaths().length(); i++){
lib_path = lib_path + " / " + QApplication::libraryPaths().at(i);
}
QString start = QString::number(QCoreApplication::startingUp());
QMessageBox::information(0, "BDD init",
"Drivers available: " + my_drivers
+ " \nHostname: " + this->db.hostName()
+ "\nDB name: " + this->db.databaseName()
+ "\nUsername: " + this->db.userName()
+ "\nPW: " + this->db.password()
+ "\n\n" + lib_path + "\n" + start
);
if(this->db.isOpen()){
QMessageBox::information(0, "BDD init", "Already open.");
}
else{
if(this->db.open()){
QMessageBox::information(0, "BDD init", "Opened.");
}
else{
QMessageBox::critical(0, "BDD init", "Not opened.\n" + this->db.lastError().text());
}
}
}
There are at least 3 possible solutions:
Find all .dll paths are correct with your favourite process monitor
Make sure all .dll is in the same arch as your .exe, which is x86 (32bit)
Debug with QPluginLoader
Simplest way to create "deploy" folder for you windows Qt5 aplication is using windeployqt tool
Create empty directory, copy your app.exe file and than run windeployqt app.exe
Check out the docs http://doc.qt.io/qt-5/windows-deployment.html#the-windows-deployment-tool

Hiding initial value in Imported Database Model of Enterprise Architect

I am currently creating database model by doing reverse-engineering MS SQL Server 2008 into Sparx's Enterprise Architect version 10.
I have been able to import tables, and hide items that are not required (such operations and stereotypes). However, I did not find the option to hide for Column Initial values when importing tables or in diagram properties, which left me the option to edit each column one by one (time consuming).
Do I miss any configuration to hide the Initial value? If such configuration does not exist, what is the best method to hide/remove the Initial value without configuration?
Finally got the solution by creating EA script. Feels free to use and enhance it :)
!INC Local Scripts.EAConstants-JScript
function OnProjectBrowserScript()
{
// Show the script output window
Repository.EnsureOutputVisible( "Script" );
var treeSelectedType = Repository.GetTreeSelectedItemType();
switch ( treeSelectedType )
{
case otElement: // if select table
{
removeInitial(Repository.GetContextObject());
break;
}
case otPackage: // if select package containing table
{
var selectedObject as EA.Element;
selectedObject = Repository.GetContextObject();
for ( var i = 0 ; i < selectedObject.Elements.Count ; i++ )
{
removeInitial(selectedObject.Elements.GetAt( i ));
}
break;
}
default:
{
// Error message
Session.Prompt( "This script does not support items of this type.", promptOK );
}
}
}
function removeInitial(selectedObject)
{
for (var i = 0 ; i < selectedObject.Attributes.Count; i++)
{
var attrib as EA.Attribute;
attrib = selectedObject.Attributes.GetAt(i);
attrib.Default = "";
attrib.Update();
}
Session.Output("finished updating " + selectedObject.Name);
}
OnProjectBrowserScript();

create cuda context manager failed

I'm implementing fluid simulator using PhysiX. Unfortunately sth is wrong with cuda context manager and I have a problem with recognizing what it is. I have an init method which looks like this:
void InitializePhysX() {
bool recordMemoryAllocations = true;
const bool useCustomTrackingAllocator = true;
PxAllocatorCallback* allocator = &gDefaultAllocatorCallback;
PxErrorCallback* error = &gDefaultErrorCallback;
PxFoundation* mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, *allocator, *error);
if(!mFoundation)
printf("PxCreateFoundation failed!\n");
PxProfileZoneManager* mProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(mFoundation);
if(!mProfileZoneManager)
printf("PxProfileZoneManager::createProfileZoneManager failed!\n");
#ifdef PX_WINDOWS
pxtask::CudaContextManagerDesc cudaContextManagerDesc;
pxtask::CudaContextManager* mCudaContextManager = pxtask::createCudaContextManager(*mFoundation, cudaContextManagerDesc, mProfileZoneManager);
if( mCudaContextManager ){
if( !mCudaContextManager->contextIsValid() ){
mCudaContextManager->release();
mCudaContextManager = NULL;
printf("invalid context\n");
}
} else {
printf("create cuda context manager failed\n");
}
#endif
mPhysX = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation, PxTolerancesScale(), recordMemoryAllocations, mProfileZoneManager);
if(!mPhysX)
printf("PxCreatePhysics failed!\n");
...
}
When I try to run my application it occures that mCudaContextManger is never created properly. "create cuda context manager failed" is being wrote on the console and:
"....\LowLevel\software\src\PxsContext.cpp (1122) : warning : GPU operation faied. No px::CudaContextManager available.
....\SimulationController\src\particles\ScParticleSystemSim.cpp (73) : warning : GPU particle system creation failed. Falling back to CPU implementation."
I have GeForce560Ti with newest driver (error also shows up on GeForce460 on my friend's laptop). Physix is set to use GPU in NVidia Control Panel.
Does anybody know what we made wrong and how to make GPU work? Thanks in advance!
File PhysX3Gpu_x86.dll was missing. I added it and now everything is fine.

MYSQL C Connector

I have a C process that is rapidly writing to a mysql database ~10 times per second. This process uses the MySql C Connector.
After about 2 minutes of running, the process hangs and in system monitor shows
"futex_wait_queue_me"
, and also
"Can't initialized threads: error 11"
is printed to console, I assume by the C connector library(since I do not print this). Following that write, connections to mysql fail with
"MySQL server has gone away".
What could be causing this? I am only writing from 1 thread.
fyi, I am using the library as so. mutex lock and unlock are there for future as i will be multithreading the logging. The logging events in actual app will be much less frequent, but I am trying to stress it as much as possible in this particular test.
//pseudocode:
while(1)
mutexlock
connect();
mysql_query();
disconnect();
sleep(100ms);
mutexunlock
A better solution, maybe not the best
connect();
while(1)
mutexlock
if error on mysql_query();
disconnect();
connect();
sleep(100ms);
mutexunlock
//connect/disconnect functions
int DBConnector::connect()
{
if(DBConnector::m_isConnected) return 0;//already connected...
if(!mutexInitialized)
{
pthread_mutex_init(&DBLock, 0);
}
if(mysql_library_init(0, NULL, NULL))
{
LoggingUtil::logError("DBConnector.DB_connect [DB library init error] " + string(mysql_error(&DBConnector::m_SQLHandle)));
DBConnector::m_isConnected = false;
return -1;
}
if((mysql_init(&m_SQLHandle)) == NULL)
{
LoggingUtil::logError("DBConnector.DB_connect [DB mysql init error] " + string(mysql_error(&DBConnector::m_SQLHandle)));
DBConnector::m_isConnected = false;
return -1;
}
if((mysql_real_connect(&DBConnector::m_SQLHandle, host.c_str(), user.c_str(), pw.c_str(), db.c_str(), port, socket.c_str(), client_flags)) == NULL)
{
LoggingUtil::logError("DBConnector.DB_connect [DB Connect error] " + string(mysql_error(&DBConnector::m_SQLHandle)));
DBConnector::m_isConnected = false;
return -1;
}
DBConnector::m_isConnected = true;
return 0;
}
int DBConnector::disconnect()
{
DBConnector::m_isConnected = false;
mysql_close(&DBConnector::m_SQLHandle);
mysql_library_end();
return 0;
}
Try to not call
mysql_library_init(0, NULL, NULL);
and
mysql_library_end();
at each connection attempt.
Also your second idea of not reconnecting at every mysql-access is much better as establishing a connection will always take some time/resource. For nothing in your case.
After a query has failed, you don't need to re-connect to the database.