I have some difficult to make a connection with my existing sqlite db in c#. I want to make it for a WPF application.
This is my code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Data.SQLite;
using Finisar.SQLite;
namespace Ebios_WPF
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
// We use these three SQLite objects:
Finisar.SQLite.SQLiteConnection sqlite_conn;
Finisar.SQLite.SQLiteCommand sqlite_cmd;
Finisar.SQLite.SQLiteDataReader sqlite_datareader;
// create a new database connection:
sqlite_conn = new Finisar.SQLite.SQLiteConnection("Data Source=existingDB.db; Version=3;");
// open the connection:
sqlite_conn.Open();
When I put an existing sqlite DB in argument I have an XamlParseException:
sqlite_conn = new Finisar.SQLite.SQLiteConnection("Data Source=existingDB.db; Version=3;");
but if i create a new database it works :
sqlite_conn = new Finisar.SQLite.SQLiteConnection("Data Source=NewDB.db; Version=3;New=True;");
Thank you for your help :)
Regards
I had this issue (and same error message) and found that sqlite.interop.dll was not automatically output/copied to where it should be in the main WPF project.
I have a class project ("Repository"), which uses System.Data.Sqlite.Core from Nuget. When I build that project, it outputs to it's bin\Debug\ directory, and it creates two sub-directories: "x64" and "x86" with sqlite.interop.dll in each. These directories are needed in the main (WPF) project, but are not moved there on build. So, to manage this, I've manually created a x64 and x86 folder in the Debug and Release bin directories of the main WPF and copy over sqlite.interop.dll. I've added this to my post build like so (first create the folders x64 and x86). "Repository" is the name of my project where the Sqlite Nuget package was installed.
copy "$(ProjectDir)Repository\bin\$(ConfigurationName)\x64\*.*" "$(ProjectDir)\bin\$(ConfigurationName)\x64\" /Y
copy "$(ProjectDir)Repository\bin\$(ConfigurationName)\x86\*.*" "$(ProjectDir)\bin\$(ConfigurationName)\x86\" /Y
I was able to resolve this in visual studio, but when I went to release the software and create an .msi, I forgot about the directories and had to also create them for my .msi.
I haven't tried it, but maybe you can just install Sqlite Nuget package into your WPF project.
Related
I was trying out the Metro UI to create a C# application so I was testing out the framework tools in a new project. I've followed the instructions from https://n-a-r-w-i-n.github.io/MetroSet-UI/#how-to-use, as well as watching youtube videos where they install it via the Package Manager Console. All result in the same error I have been getting when I try to add an item to the form. Encountered Error
After running the design view goes completely blank and I cannot edit or do anything in that regard. Here is the code used for Form1.
using MetroFramework.Forms;
using MetroFramework;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Test_App
{
public partial class Form1 : MetroForm
{
public Form1()
{
InitializeComponent();
}
}
}
I have notices I also have this warning.
Severity: Warning
Code: NU1701
Description: Package 'MetroModernUI 1.4.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
Project: Test App.csproj
Line: 1
Please assist me to get a hang of this! Thank you for your time in advanced! :)
I am trying to implement SQLite in a Xamarin solution using Visual Studio. However, i can not find the proper way to implement an SQLiteAsyncConnection.
I am following along a tutorial, which just passes a string to the constructor of the SQLiteAsyncConnection, however this is (no longer?) accepted. I googled to find a newer solution and almost everywhere found the solution to add a platform to the constructor, however that results in an error for me.
I think i might not have added the correct NUGet packages to the project(s). I have added the sqlite-net-pcl package to both the shared project and the android project.
I have also updated all NUGet packages today, rebuilt the solution and even deleted the /bin and /obj folder and it still is not working.
using System.IO;
using SQLite.Net;
using SQLite.Net.Async;
using Xamarin.Forms;
using SQLiteTest.Droid;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
[assembly: Dependency(typeof(SQLiteDB))]
namespace SQLiteTest
{
public class SQLiteDB : ISQLiteDB
{
public SQLiteAsyncConnection GetAsyncConnection()
{
const string fileName = "test.db3";
var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var path = Path.Combine(documentsPath, fileName);
var platform = new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid();
var cwLock = new SQLiteConnectionWithLock(platform, new SQLiteConnectionString(path, true));
var connection = new SQLiteAsyncConnection(() => cwLock);
return connection;
}
}
}
The error i get is:
Error CS0234 The type or namespace name 'Platform' does not exist in the namespace 'SQLite.Net' (are you missing an assembly reference?) SQLiteTest.Android D:\Mobile Apps\Mosh\SQLiteTest\SQLiteTest\SQLiteTest.Android\SQLiteDB.cs
Well, I am pretty sure you have not added the SQLite.Net.Platform.XamarinAndroid.dll package to your native Android project which is causing this issue when you use this dependency service.
If you are using SQLite-net and or SQLite.Net-PCL look for the Xamarin.Android platform dll int he path below:
packages\SQLite.Net-PCL.3.1.1\lib\MonoAndroid\`SQLite.Net.Platform.XamarinAndroid.dll`
I want to use novacode-docx in cs-script. how can I give correct reference to the assembly. I tried following but didn't work around the assembly reference missing.
//css_reference D:\lib\DocX.dll;
using System;
using System.Diagnostics;
using System.Windows.Forms;
class Script
{
[STAThread]
static public void Main(string[] args)
{
using (DocX doc = DocX.Create(#"C:\Users\name\Desktop\test.docx"))
{
doc.PageLayout.Orientation = Orientation.Landscape;
var table = doc.AddTable(12, 2);
doc.InsertTable(table);
doc.Save();
}
}
}
You cannot reference an explicit path like that for presumably security reasons. The assembly must be placed in one of the following locations and referenced as //css_reference DocX.dll;
File location The assembly to be loaded must be from one of the following locations (the order indicates the assembly search
priority):
the same directory where the script is
Default Script Library directory Script Library (%CSSCRIPT_DIR%\Lib)
Custom Script Library directory(s) (specified in the configuration console SearchDirs)
GAC
See here for more info: http://www.csscript.net/help/using_.net_assemblies.html
Drop the Docx.dll into the same folder as where the cs script is and try this:
//css_reference DocX.dll;
using System;
using System.Diagnostics;
using System.Windows.Forms;
using Novacode;
class Script
{
[STAThread]
static public void Main(string[] args)
{
using (DocX doc = DocX.Create(#"C:\Users\name\Desktop\test.docx"))
{
doc.PageLayout.Orientation = Orientation.Landscape;
var table = doc.AddTable(12, 2);
doc.InsertTable(table);
doc.Save();
}
}
}
DocX seems to be available on NuGet, so I would heavily recommend fetching the dependency from there rather than having it in a file on your local system. (This helps ensuring repeatable builds, should you share this code with others, with packaging your application, and it will also make it easier to upgrade DocX if a new version is released.)
If you're using Visual Studio, you can right-click the project in Solution Explorer and choose "Manage NuGet Packages..." to open a dialog that helps you install the package, or you can open Package Manager Console and enter Install-Package DocX.
If you're building on .NET Core without Visual Studio, just add "DocX": "1.0.0.19" to the dependencies node of your project.json.
When the package is installed, you can just do using DocX; like with any other namespace import.
Have you read this link
To add a reference in Visual C#
In Solution Explorer, right-click the project node and click Add Reference.
In the Add Reference dialog box, select the tab indicating the type of component you want to reference.
Select the components you want to reference, and then click OK.
Without VS:
Go to the csproj file there is a <ItemGroup> where references can be added:
<ItemGroup>
<Content Include="libs\...">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
...
There you can add libs.
both required in order to use docx.
//css_reference DocX.dll;
using Novacode;
You can also give reference to any place like
//css_reference D:\lib\DocX.dll;
using Novacode;
I use VS2005 on Windows Vista.
I create a very simple Windows application in C# using .NET 2.0, a form with a close button.
Due to a necessary library, I need the VS-option target platform "x86". If I build on Vista and transfer the application to a X64 Windows 7 computer, the application requires administrator rights for execution (UAC-Message-Dialog), which I want to avoid.
If using the VS-option target platform "anyCPU", this works fine, but I need a solution for the target platform "x86".
Can anybody help me?
What I want to do is to change the code or the project configuration to avoid the UAC-Message-Dlg on Windows7 (x64). But I don’t know what I have to do. I need the option “x86”, because we want to use an x86 library. The test code is totally simple (see below), so I presume the problem is in the project configuration:
// Project code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Updater2
{
public partial class Form1 : Form
{
public Form1( )
{
InitializeComponent( );
}
private void toolStripButton1_Click( object sender, EventArgs e )
{
Close( );
} // -- toolStripButtonClose_Click
} // - Form1
}
Chances are you are trying to write files to the C:/ or C:/Program Files folder. Try writing any files to the %Current User% folder to avoid UAC. Apart from that, without seeing any of your code, I can't offer much more of a solution.
The problem is the word "Update" in the program name.
When an executable has words like "Update", "Install" or "Setup" in its name, Windows assumes it may be an installer which will most likely require administrative rights. So, these programs are forced to run with an elevation prompt on UAC-enabled systems.
It's not just the executable name either. If renaming the file does not solve the problem, the application might have these keywords in its version information too. Having the following will result in the same behavior:
[assembly: AssemblyTitle("Setup DVD Player")]
[assembly: AssemblyProduct("Instal President")] // Yes, even with the misspelling.
Easy way out is to rename the application and to avoid using these keywords.
Proper way out is including an application manifest in the executable.
I'm new in .Net and I'm now trying to write a plugin for windows live writer because I prefer to publish blogs using it rather than using the web editors. And I want to develop some small plugins for my daily use. But after I created a class libarary project and built it following the steps as some developers described, the WLW does not load the plugin so I don't know how to debug.
My Code:
using System;
using System.Collections.Generic;
using System.Text;
using WindowsLive.Writer.Api;
using System.Windows.Forms;
namespace Insert_Colorful_Table
{
[WriterPluginAttribute
("f7581112-dddd-47c9-9db0-46987a2aaae1",
"Insert Colorful Table",
Description = "Helps you create a beautiful table.",
ImagePath = "icon.gif",
PublisherUrl = "http://ggicci.blog.163.com")]
[InsertableContentSource("Insert Colorful Table")]
public class Plugin : ContentSource
{
public override DialogResult CreateContent
(IWin32Window dialogOwner, ref string content)
{
content = #"<table><tr><td>Ggicci</td></tr></table>";
return DialogResult.OK;
}
}
}
I did configure the 'Build Events' of the project and set the 'Build Action' of the image to 'Embedded Resource'. And no errors occured when building my project.
okay, I've worked out what went wrong. Windows Live Writer supports plugins that are built with either the Microsoft .NET Framework version 1.1 or 2.0. Writer requires users to have .NET 2.0 present to install the application. But I used .NET 4.0. So when I changed target framework to 2.0, then it worked well.