Qt QSql: cannot create a new MDB-File per ODBC - qt

I am using the following code to create an NEW MS Access file using the SQL API from Qt.
QString strDatabaseName;
if (strExt == ".DB")
{
oQtDatabase = QSqlDatabase::addDatabase(_TN("QSQLITE"), _TN("Redline_DB"));
strDatabaseName = strDatei;
}
if (strExt == ".MDB" || strExt == ".ACCDB")
{
oQtDatabase = QSqlDatabase::addDatabase(_TN("QODBC"), _TN("Redline_MDB"));
strDatabaseName = _TN("Driver={Microsoft Access Driver (*.mdb, *.accdb)};FIL={MS Access};DSN='';DBQ=") + QString::fromLatin1(strDatei);
}
oQtDatabase.setDatabaseName(strDatabaseName);
if (!oQtDatabase.open())
throw oQtDatabase.lastError();
The part for SQLite is succesful in creating a .DB File. Unfortunately QODBC throws an error:
[Microsoft][ODBC-Treiber für Microsoft Access] Datei '(unbekannt)'
nicht gefunden. QODBC3: Unable to connect
Which means: ODBC-driver for Microsoft Access, File 'unkown' not found
I have to mention that the connection string works well with an existing Access file.
Thanks in advance for your help.

Related

c++builder FDConnection to SQLite after compile the exe

I created a Script with c++Builder 11 with Datas stored in a sqlite3 db File.
To Connect to the Sqlite3.db, i used the FireDAC-Connection inside c++builder and all works fine.
In the Connection-Manager (DataExplorer) of C++Builder i set the Path to "D:\TEST.db".
If i share the Compiled Exe to another PC, then its possible there is no Drive D.
I tried in Connection-Manager to use only the Filename "TEST.db" without Path, but ends in a FireDAC Error Message: "FireDAC..Stan..Definition .. not found in []"...
i also tried "#scriptdir & "\TEST.db" in the Connections-Manager.. but dont works, too...
how can i save my TEST.db (sql3-database) in the ScriptDir if the Connection is fix via "FDConnection1" ????
thanks for any help..
Greeting.
You could use the BeforeConnect for pointing your FDConnection Object to the correct database file. In the example below it would point to a database file named "test.db3" which is located in your exe's folder:
void __fastcall TForm4::FDConnection1BeforeConnect(TObject *Sender)
{
dynamic_cast< TFDConnection * >( Sender )->Params->Database =
ExtractFileDir( Application->ExeName ) + "\\test.db3";
}
void __fastcall TForm4::Button1Click(TObject *Sender)
{
FDConnection1->Connected = true;
}
best regards, Herwig

File path issue in mac

nopCommerce version: 4.1
I am using nopCommerce version 4.1 on mac os with visual studio for mac, when I run this solution, I get error on creating path.
Plugin 'Must be assigned to customer role'. Could not load file or
assembly
'/Users/alireza/Desktop/NopCommerce/Presentation/Nop.Web/Plugins\bin/Nop.Plugin.DiscountRules.CustomerRoles.dll'.
The system cannot find the file specified.\n\nCould not load file or
assembly
'/Users/alireza/Desktop/NopCommerce/Presentation/Nop.Web/Plugins\bin/Nop.Plugin.DiscountRules.CustomerRoles.dll'.
The system cannot find the file specified.\n\n
I found the solution by myself:
path = Environment.OSVersion.Platform == PlatformID.Win32NT
? path.Replace("~/", string.Empty).TrimStart('/').Replace('/', '\\')
: path.Replace("~/", string.Empty).TrimStart('/');
in the file opCommerce_4.10_Source/Libraries/Nop.Core/Infrastructure/NopFileProvider.cs
replace the the following function
public virtual string MapPath(string path)
with the following code :
public virtual string MapPath(string path)
{
// path = path.Replace("~/", string.Empty).TrimStart('/').Replace('/', '\\');
path = Environment.OSVersion.Platform == PlatformID.Win32NT
? path.Replace("~/", string.Empty).TrimStart('/').Replace('/', '\\')
: path.Replace("~/", string.Empty).TrimStart('/');
return Path.Combine(BaseDirectory ?? string.Empty, path);
}

Unable to create folder with RCurl

I'm having trouble using the ftpUpload() function of RCurl to upload a file to a non-existent folder in an SFTP. I want the folder to be made if its not there, using the ftp.create.missing.dirs option. Here's my code currently:
.opts <- list(ftp.create.missing.dirs=TRUE)
ftpUpload(what = "test.txt",
to "sftp://ftp.testserver.com:22/newFolder/existingfile.txt",
userpwd = paste(user, pwd, sep = ":"), .opts = opts)`
It doesn't seem to be working as I get the following error:
* Initialized password authentication
* Authentication complete
* Failed to close libssh2 file
I can upload a file to an existent folder with success, its just when the folder isn't there I get the error.
The problem seems be due the fact you are trying to create the new folder, as seen in this question: Create an remote directory using SFTP / RCurl
The error can be found in Microsoft R Open git page:
case SSH_SFTP_CLOSE:
if(sshc->sftp_handle) {
rc = libssh2_sftp_close(sshc->sftp_handle);
if(rc == LIBSSH2_ERROR_EAGAIN) {
break;
}
else if(rc < 0) {
infof(data, "Failed to close libssh2 file\n");
}
sshc->sftp_handle = NULL;
}
if(sftp_scp)
Curl_safefree(sftp_scp->path);
In the code the parameter rc is related to libssh2_sftp_close function (more info here https://www.libssh2.org/libssh2_sftp_close_handle.html), that tries close the nonexistent directory, resulting in the error.
Try use curlPerform as:
curlPerform(url="ftp.xxx.xxx.xxx.xxx/";, postquote="MkDir /newFolder/", userpwd="user:pass")

can't find IfxBulkCopy in IBM.Data.Informix 2.81.0.0

Q:
My question consists of two parts:
1- I want to use the following class IfxBulkCopy to insert large amount of data but this class doesn't exist in the dll IBM.Data.Informix 2.81.0.0 how to fix this problem.?
Note : the class exist in the IBM.Data.Informix 9.0.0.2 !but i can't use this version because we use an old version of the informix.
When i use the new version i get the following exception :
Invalid argument
StackTrace = " at IBM.Data.Informix.IfxConnection.ReplaceConnectionStringParms(String szValue, IfxConnSettings& connSettings)\r\n at IBM.Data.Informix.IfxConnection.set_ConnectionString(String value)\r\n at Common.DBConnectionForInformix..ctor(String ConnectionStr...
My .cs:
public static void InsertAsBulk(DataTable dt)
{
using (IfxConnection cn = new IfxConnection(ConfigurationManager.ConnectionStrings["aa"].ToString()))
{
cn.Open();
using (IfxBulkCopy copy = new IfxBulkCopy(cn))
{
copy.ColumnMappings.Add(1, 2);
copy.ColumnMappings.Add(2, 3);
copy.ColumnMappings.Add(3, 4);
copy.ColumnMappings.Add(4, 5);
copy.ColumnMappings.Add(5, 6);
copy.ColumnMappings.Add(6, 7);
copy.DestinationTableName = "schday";
copy.WriteToServer(dt);
}
}
}
2- Is the IfxBulkCopy use the transaction concept during the insertion operation or may result inconsistent data also .
Your connection string is fine. Do you have multiple versions of driver installed? I had same problem when I installed OAT, Informix driver and Informix Client SDK on same machine.
This solved my problem:
1. Uninstallation of driver and client sdk + windows restart
2. Installation of Client SDK together with data server driver
3. Checking system PATH variable. I added
C:\Program Files\IBM Informix Client SDK\bin
C:\Program Files\IBM Informix Client SDK\bin\netf20
to system PATH. I'm not sure what was the problem, maybe just changing PATH variable (without unistallation) can fix it.

Com Exception: Word was unable to read this document. It may be corrupt

I have a web app that takes some client info and produces a letter for each client. Everything works good in my test environment, but on the production server I get an error that says the file is corrupt. I can open the .dotx file in word just fine on the server but not via code. Please help. Here is my code:
Object oMissing = System.Reflection.Missing.Value;
Object oTrue = true;
Object oFalse = false;
Word.Application oWord = new Word.Application();
Word.Document oWordDoc = new Word.Document();
oWord.Visible = false;
Object oTemplatePath = Request.PhysicalApplicationPath + "letters\\" + letter.letter_data; //samplehollisletter.dotx";
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
foreach (Word.Field myMergeField in oWordDoc.Fields)
{
iTotalFields++;
Word.Range rngFieldCode = myMergeField.Code;
String fieldText = rngFieldCode.Text;
if (fieldText.StartsWith(" MERGEFIELD"))
{
Int32 endMerge = fieldText.IndexOf("\\");
Int32 fieldNameLength = fieldText.Length - endMerge;
String fieldName = fieldText.Substring(11, endMerge - 11);
fieldName = fieldName.Trim();
if (fieldName == "letter_title")
{
myMergeField.Select();
oWord.Selection.TypeText(acct.letter_title);
}
if (fieldName == "account_id")
{
myMergeField.Select();
oWord.Selection.TypeText(acct.account_id);
}
if (fieldName == "address")
{
myMergeField.Select();
oWord.Selection.TypeText(acct.PEOPLE.home_address + "\r\n" + acct.PEOPLE.home_city + ", " + acct.PEOPLE.home_state + " " + acct.PEOPLE.home_zip);
}
if (fieldName == "greeting_title")
{
myMergeField.Select();
oWord.Selection.TypeText(acct.greeting_title);
}
if (fieldName == "service_name")
{
myMergeField.Select();
oWord.Selection.TypeText((acct.SERVICEs.FirstOrDefault()).service_name);
}
if (fieldName == "service_date")
{
myMergeField.Select();
oWord.Selection.TypeText((acct.SERVICEs.FirstOrDefault()).service_date.ToString());
}
}
}
oWordDoc.PrintOut();
oWordDoc.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges);
Thread.Sleep(2000);
oWord.Quit();
The Error is:
Server Error in '/Tracker2' Application.
Word was unable to read this document. It may be corrupt.
Try one or more of the following:
* Open and Repair the file.
* Open the file with the Text Recovery converter.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Word was unable to read this document. It may be corrupt.
Try one or more of the following:
* Open and Repair the file.
* Open the file with the Text Recovery converter.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[COMException (0x800a141f): Word was unable to read this document. It may be corrupt.
Try one or more of the following:
* Open and Repair the file.
* Open the file with the Text Recovery converter.]
Microsoft.Office.Interop.Word.Documents.Add(Object& Template, Object& NewTemplate, Object& DocumentType, Object& Visible) +0
Tracker.RunLetter2.Button1_Click(Object sender, EventArgs e) in C:\Users\Ethan\Documents\Visual Studio 2010\Projects\EstateTracker\Tracker\RunLetter2.aspx.cs:52
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691
I know it is time that this item has been opened, but as I had not found the answer anywhere, following solution for those who need it.
1 - In IIS, the application pool used by the application, change the Identity attribute to LocalSystem
2 - Create a folder called Desktop within the following directories on the server:
C:\Windows\System32\config\systemprofile
and
C:\Windows\SysWOW64\config\systemprofile
After that, give full permission for these two folders to the user group IIS: IIS_IUSRS
This will cause this user to have a "desktop" to work, thereby achieving the IIS Word use the library.
I rough it helps someone.
I have discovered that the issue stems from permissions of a WCF call using BasicHTTPBinding endpoints. When a call is made using this type of endpoint, the service assumes the use of an IIS account which does not have a desktop to open word. This is a requirement of the account to automate word. Even when you have a service, that launches a windows application, that launches word, the entire set of events will be given the privilage of the original WCF call and will result in this error.
My solution, while not great, nor what I really want, does work for the time being. I created a Queue table in the database. I then have the web app insert a request for a task to be completed. then on the server I have a standalone application that checks the queue for requests every 60 seconds and processes the request. Its not the best method boe like I said, it does work.

Resources