I am making an UWP in which I need to access a database. To do so I first downloaded and installed the SQL Universal Windows Platform from this link:
https://sqlite.org/download.html
After this was done I added it as a reference and included it in my code with:
#include <sqlite3.h> //Not sure if I need to make any other changes for this to work
To troubleshoot I have just a button and a textbox. This is the code that it's been run when the button is clicked:
int rc;
sqlite3 *testDB;
if (SQLITE_OK == (rc = sqlite3_open("signers.db", &testDB))) {
Message->Text = "It worked!";
}
else {
Message->Text = "Can't open Database";
}
signers.db it's a database that I created using SQLite so I could have some data to read from my program. Everytime I run the program the text "Can't open Database" appears. I've tried every solution that I see online but none seem to work for me thus I think that I overseeing something. I am fairly new at UWP and also at using databases.
If you need any additional information feel free to ask for it.
If you have the database in your package folder, then it is read-only. You need to use sqlite3_open_v2 and pass the SQLITE_OPEN_READONLY flag.
If you want to open the database for read / write then you need to copy it to your local folder first.
(Also make sure you actually have the database set to deploy; in the Properties window make sure it is set to Content and that it will be copied to the output directory).
According to
https://learn.microsoft.com/en-us/windows/uwp/files/file-access-permissions
you have some limitations to the location where the db file you want to open is located. sqlite itself should work. Try opening a db in a folder specified in the article.
Could also be just a corrupted db file. Did you try to create an empty one?
Related
There's probably a simple solution to this but I just can't find it.
When I open my application I want to open an sqlite database one directory up from the current directory the program is running from. It is the 'Database' directory.
This is the relevant lines of code. Nothing else matters at this point.
The database doesn't open. Don't want to create a database, I want to use an existing one.
string d_base = "Database/settings.db";
if(SQLITE_OK == sqlite3_open_v2(d_base.c_str(),&handle,SQLITE_OPEN_READWRITE ,NULL))
{
// does something.
}
I am new to C++ (was previously into Java) and I am trying to find my way around it for the past few days. I am having a Sqlite DB in my local Machine which I am trying to access in order to display the results of a query on a Windows Application Form using DataGridView.
I was able to locate a good place to start here but later discovered that this was more concentrated towards SQL server and not SQLite and the code failed when I tried to replace this part of code
String^ connectionString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
with this
String^ connectionString = "Data Source=C:\\data\\test.db"
to point to my local Sqlite DB (test.db).
Upon more digging I found that I was able to find C# examples for linking SQLite DB to Windows Form Application here. Next I tried to convert the C# code provided into a C++ one but failed.
I have been looking all around for simple C++ examples which would help me understand how to link a Sqlite DB to a Windows Form Application but am not able to do so yet.
I would appreciate it greatly if anyone could point me to one such example.
To access SQLite DB from managed code use System.Data.SQLite library. It's a managed library supported by SQLite Development Team and you can use it with managed C++ also. Here is the sample:
using namespace System::Data::SQLite;
using namespace System::Text;
void Test()
{
SQLiteConnection ^db = gcnew SQLiteConnection();
try
{
db->ConnectionString = "Data Source=C:\\data\\test.db";
db->Open();
// Do the job here
db->Close();
}
finally
{
delete (IDisposable^)db;
}
}
I made a setup packadge of some program in Visual Studio 2008. So on my PC after installation everything works well. On others PC when you just click on database connection option it just crashes.
Well, here's the error
I think it appears at this line
database = QSqlDatabase::addDatabase("QPSQL");
in database initialization part because of message about DB apperas and everything seems work fine until this line.
Here's full function
void DatabaseManagement::initDatabase(){
QMessageBox::information(this, "error tracking step 5", " DB ADDED");
database = QSqlDatabase::addDatabase("QPSQL");
QStringList sdrivers = QSqlDatabase::drivers();
//output all avalible drivers
QString driver = sdrivers[0];
for(int i = 0; i< sdrivers.size();i++)
QMessageBox::information(this, "Driver info", sdrivers[i]);
}
database variable here is global for DatabaseManagement class.
Also in this class I got getDatabase function which returns database variable and I use it in other class, let say in mainClass (in case if this could be cause of the problem).
What coulbe be the cause of this problem? How could I solve that?
By the way, I use Qt 4.7.4
UPD:
Well, the problem solved! I forget to add sqldrivers folder! Of course I added all necessary .dlls but for some reason program see it only in this folder. Hope it could be helpful for somebody.
By the way DependencyWalker show taht nothing was wrong with not working version (without sqldrivers folder).
My guess would be that the problem lies here (A debugger would tell you more):
QStringList sdrivers = QSqlDatabase::drivers();
//output all available drivers
QString driver = sdrivers[0];
You're accessing sdrivers[0] without checking that sdrivers contains at least one element.
I assume you didn't deploy the Qt SQL plugins correctly and thus none is found on the other computer. So fix above code (guarding it with if (!sdrivers.isEmpty())) and deploy the plugins.
The problem is more likely this line: QString driver = sdrivers[0];
I guess you forgot to provide the sql-plugin folder? %YOUR-APP-PATH%/plugins/qpsql.dll
Try adding:
if(sdrivers.size() > 0)
QString driver = sdrivers[0];
I'm developping a Qt GUI application.
My problem is that I use the console for another thread (it write his comunication in it), and the main problem is that when I create a QFileDialog (in order to select a script file), KDE is wrinting useless informations (for me at least).
Is there a way to remove all possibility from my QFileDialog to write anything into the consolethat ? Is there a trick to switch main output to another (useless) target ?
My code (but I don't think it's really gonna help you) :
void MyGUI::setPathWithFileExplorer()
{
QFileDialog dlg;
dlg.resize(320,240);
QString fileName = dlg.getOpenFileName(this, tr("Open script file"), "~/", tr("Script Files (*.js)"));
if(fileName != "")
ui->editScriptPath->setText(fileName);
}
Output :
kded(21003) Mollet::KioSlaveNotifier::onDirectoryEntered: "trash:/"
kded(21003) Mollet::KioSlaveNotifier::onDirectoryLeft: "trash:/"
kded(21003) Mollet::KioSlaveNotifier::onDirectoryEntered:
"file://[PATH TO MY USER FOLDER]" kded(21003)
Mollet::KioSlaveNotifier::onDirectoryLeft:
"file://[PATH TO MY USER FOLDER]" kded(21003)
Mollet::KioSlaveNotifier::onDirectoryEntered:
"file://[PATH TO MY USER FOLDER]" kfilemodule(21676)
KSambaSharePrivate::testparmParamValue: We got some errors while
running testparm "Load smb config files from /etc/samba/smb.conf
Loaded services file OK. WARNING: The setting 'security=ads' should
NOT be combined with the 'password server' parameter. (by default
Samba will discover the correct DC to contact automatically). WARNING:
You have some share names that are longer than 12 characters. These
may not be accessible to some older clients. (Eg. Windows9x,
WindowsMe, and smbclient prior to Samba 3.0.) "
QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed:
Permission non accordée QFileSystemWatcher: failed to add paths:
/var/lib/samba/usershares
I would suggest using kdebugdialog and then Deselect All. Here you can see an inline screenshot on my machine.
Failing that, you could always use QFile to log your output into a dedicated file, and then monitor that in a separate prompt or application.
If you go down that way, you could even take a look at the logger functionality added in 5.2 if you happen to be able to use that version.
I'm working on a project in C# that involves parsing .pst files and my group has chosen to use the Redemption library to do so. We have successfully parsed the email files in to RDOMail objects, however now we want to write a subset of those emails to a new .pst file. I have successfully written the subset to .eml files using the email.SaveAs() function, but I'm at a loss to figure out how to save that list as a .pst. I've been sifting through the documentation, however it leaves much to be desired. Can anyone who has used Redemption point me in the right direction or provide an example?? Thanks in advance for your help!
You will need to create/open a PST file using RDOSession.Stores.AddPstStore (returns RDOPSTStore object). Once you have the store, you can open/create folders (starting with the RDOStore.IPMRootFolder), create messages (RDOFolder.Items.Add) and copy old messages into new messages (RDOMail.CopyTo(RDOMail/RDOFolder)).
I have been struggling to do this for the last few hours and would like to save that time to others
You have to install redemption and add it as a reference to your project for it to work
RDOSession session = new RDOSession(); // throws exception 1
session.LogonPstStore(#"c:\temp\output.pst");
RDOFolder folder = session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox);
string[] fileEntries = Directory.GetFiles(#"C:\emlFiles\", "*.eml");
foreach (string filePath in fileEntries)
{
RDOMail mail = folder.Items.Add("IPM.Mail");
mail.Sent = true;
mail.Import(filePath, 1024);
// folder.Items.Add(mail);
mail.Save();
}
session.Logoff();
I also created a small sample windows forms app for it, I know the code is ugly but it does the trick