I'm trying to get SQLite running in Visual Studio 2012 for C#.
However after going through a set of tutorials I still get the error DllNotFoundException for the SQLite.Interop.dll.
This is the full error I receive:
Unable to load DLL 'SQLite.Interop.dll': The specified path is
invalid. (Exception from HRESULT: 0x800700A1)
I have created a reference for the System.Data.SQLite.dll. Now I found that I have to add the SQLite.Interop.dll file into my project folder but I still get this error.
Oh and BTW, this is my code, if anyone is interested:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;
namespace SQLiteWinFormCS
{
public partial class Form1 : Form
{
private SQLiteConnection _sqlCon;
private SQLiteCommand _sqlCmd;
private SQLiteDataAdapter _db;
private DataSet _ds = new DataSet();
private DataTable _dt = new DataTable();
private string _dbPath = String.Empty;
public Form1()
{
InitializeComponent();
}
private void uiOpenDB_Click(object sender, EventArgs e)
{
Console(String.Format("You clicked {0}.", ((Button)sender).Name));
this._dbPath = uiDatabaseFilepath.Text;
Console("Filepath to DB = " + this._dbPath);
Console("Attempting to open DB connection...");
this._sqlCon = new SQLiteConnection(String.Format("Data Source={0};", #"\\Some-PC\ISC\Databases\testdbs\test.db3")); // << ERROR
Console("DB connection succesfull!");
}
private void Console(string text)
{
uiConsoleOutput.AppendText(text);
uiConsoleOutput.ScrollToCaret();
}
}
}
Can anyone help me get this thing working?
Thanks in advance.
Copy the SQLite.Interop.dll file into your debug folder.
For example "Projects\sqlite test18\sqlite test18\bin\Debug" place it here.
And dont add the Interop as a reference.
Add only these references
System.Data.SQLite
System.Data.SQLite.EF6
System.Data.SQLite.EF6
This solved my problem.
And I was using Sqlite x86 under x64 OS.
Dohh...
I was probably using a wrong System.Data.SQLite.dll.
For anyone who is interested you can find the new .dll file I downloaded here:
http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
I needed the .dll for the 4.5 Framework (x86); I clicked the first download link.
Also I am using just the System.Data.SQLite.dll, no other files!
Hope this answer helps someone else. :-)
Related
Okay, so I've ran into a problem that I am having trouble finding a solution. There are plenty of solutions using visual studios properties. The issue is that I'm not using visual studios, I'm using csc.exe to compile my code.
Here's what I have so far.
exe.cmd
dll.cmd
Resource.dll
Main.csx
Rsc.csx
a.png
This is all of the code for the .cmd files and .csx files
exe.cmd
#echo off
csc.exe /target:winexe /reference:Resource.dll /out:Main.exe Main.csx
pause
dll.cmd
#echo off
csc.exe /target:library /resource:a.png /out:Resource.dll Rsc.csx
pause
Rsc.csx
using System;
using System.IO;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
namespace EmIm
{
public static class Bck
{
public static Image GetBck()
{
Bitmap bmp = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("a.png"));
Image rtn = bmp;
return rtn;
}
}
}
Main.csx
using System;
using System.IO;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using EmIm;
namespace prg
{
class class_m
{
public static void Main()
{
Form f1 = new Form();
try
{
f1.BackgroundImage = Bck.GetBck();
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
f1.ShowDialog();
}
}
}
When I run this, I get a messagebox that displays value of 'null' is not valid for 'stream'
What steps do I need to take to be able to access a.png with reflection, I have checked to make sure a.png is the correct name in the assembly. Any help would be greatly appreciated. Thanks :)
A large thanks to Hans Passant for providing the simple solution to this problem. I had no idea even where to look to find out how to answer this problem, but he summed it up in a single comment.
only one file had to be altered in order for the program to work
new Rsc.csx file
using System;
using System.IO;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using System.Runtime.CompilerServices;
namespace EmIm
{
public static class Bck
{
[MethodImpl(MethodImplOptions.NoInlining)]
public static Image GetBck()
{
Bitmap bmp = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("a.png"));
Image rtn = bmp;
return rtn;
}
}
}
Once again, thanks Hans Passant for that quick fix to my problem, hopefully any other programmers stubborn enough to avoid Visual Studios could possibly look to this to find a solution that works without it. Have fun programming :)
I am working on a visual studio project in which I have a webpage I would like to display in webbrowser. Currently I have a folder named resources in which I have copied all the required html,js and css files, but I don't know how to point it in the project. Any ideas? Thank you.
Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
string appPath = Assembly.GetEntryAssembly().Location;
string filename = Path.Combine(Path.GetDirectoryName(appPath), "resources\\index.html");
notes.Navigate(filename);
}
}
}
Thank you.
Update
I have pasted the contents of the resources folder directly in the project, and tried multiple options suggested in the URL. Unfortunately, nothing is working, and I am new to Visual studio, so don't even have an idea what's going wrong. Updated code :
private void Form1_Load(object sender, EventArgs e)
{
//string curDir = Directory.GetCurrentDirectory();
//this.notes.Url = new Uri(String.Format("file:///resources/index.html", curDir));
string applicationDirectory = Path.GetDirectoryName(Application.ExecutablePath);
string myFile = Path.Combine(applicationDirectory, "index.html");
notes.Url = new Uri("file:///" + myFile);
}
If you want to open a link in a browser from your desktop app (e.g. "show in the browser" button in WinForms app), you can use System.Diagnostics.Process.Start("http://localhost:42") as it's discussed here (production code will have some non-localhost link there).
Before that you should host your website on local IIS and specify the port (e.g. 42) there.
On the other hand, if you want to create a web application (with C# back-end code), you should use another type of project (not WinForms), e.g. ASP.NET MVC
EDIT:
System.Diagnostics.Process.Start also works with local files, e.g. System.Diagnostics.Process.Start(#"C:\Sites\index.html");
EDIT 2:
You also could use application directory e.g. System.Diagnostics.Process.Start(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, #"site\index.html")) to keep paths in your app relative
I was working through the MSDN tutorial for Crystal Reports, and I get to the Binding the Embedded Report to the CrystalReportViewer Control step:
When I try the build, it tells me that I am missing my using declaration for Hierarchical_Grouping class. This brings up two questions for me...
What is the namespace for this class definition?
Is there an easy way of determining the namespace of a given class?
In another answer I saw the 'ALT, SHIFT, F10' and the 'CTRL, [period]' suggestions for intellisense, but they don't work in my Visual Studio.
I'm sure I have done something ridiculously stupid....sorry in advance....
Here's the code for the form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace CrystalTest3
{
public partial class Form1 : Form
{
private Hierarchical_Grouping hierarchicalGroupingReport;
public Form1()
{
InitializeComponent();
}
private void ConfigureCrystalReports()
{
hierarchicalGroupingReport = new Hierarchical_Grouping();
crystalReportViewer.ReportSource = hierarchicalGroupingReport;
}
private void Form1_Load(object sender, EventArgs e)
{
ConfigureCrystalReports();
}
}
}
I am assuming that you are referring to this tutorial.
The Hierarchical_Grouping seems to refer to the report file - which will contain the class named Hierarchical_Grouping. Have you added the report to your project?
The report should be somewhere in these Sample Reports Directories.
When I run a c# application through Visual Studio 2010, where R is integrated, I get the error: The program can't start because Rlapack.dll is missing from your computer. Try reinstalling the program to fix this problem.
I tried reinstalling the program but it did not work.
I also tried putting it in the folder that has the Matrix in it but it did not work. This solution was suggested in StackOverflow Q.
I am running 64-bit Windows 7! The application is 32-bit.
There are two dll's. One in a folder called i386, and another one in the folder x64.
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using RDotNet;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string dlldir = #"D:\Program Files\R-2.15.0\bin\i386";
bool r_located = false;
while (r_located == false)
{
try
{
REngine.SetDllDirectory(dlldir);
REngine.CreateInstance("RDotNet");
r_located = true;
}
catch
{
MessageBox.Show(#"Unable to find R installation's \bin\i386 folder.
Press OK to attempt to locate it.");
}
}
}
}
}
I realize this has been answered, but that was back in 2012. For anyone still having this problem with R version 3.4.3 or later in 2018, especially while trying to follow the simple example from the r.net home page, below is what I did to fix it:
In your code, before the line REngine engine = REngine.GetInstance();, add this line REngine.SetEnvironmentVariables(#"C:\Program Files\R\R-3.4.3\bin\x64", #"C:\Program Files\R\R-3.4.3");.
right click project, go to build and uncheck "Prefer 32-bit".
copy Rlapack.dll from C:\Program Files\R\R-3.4.3\bin\i386
paste in both C:\Program Files\R\R-3.4.3\library\stats\libs\i386 and C:\Program Files\R\R-3.4.3\library\Matrix\libs\i386
copy Rlapack.dll from C:\Program Files\R\R-3.4.3\bin\x64
paste in both C:\Program Files\R\R-3.4.3\library\stats\libs\x64 and C:\Program Files\R\R-3.4.3\library\Matrix\libs\x64.
Such a pain, but that is what finally got it to work for me.
Here is what I just did and it worked: I put the dll in the bin folder of my application.
Try setting path variable before caling the dll:
var envPath = Environment.GetEnvironmentVariable("PATH");
string s = null;
if (Environment.Is64BitProcess)
s = #"C:\Program Files\R\R-2.15.0\bin\x64";
else
s = #"C:\Program Files\R\R-2.15.0\bin\i386";
Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + s);
Hi every one I am getting the following error: "The name 'ConfigurationManager' does not exist in the current context"
// namespaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
namespace Database1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string GetConnectionString(string strConnection)
{
//variable to hold our connection string for returning it
string strReturn = "";
//check to see if the user provided a connection string name
//this is for if your application has more than one connection string
if (!string.IsNullOrEmpty(strConnection)) //a connection string name was
{
//get the connection string by the name provided
strReturn = ConfigurationManager.ConnectionStrings[strConnection].ConnectionString;
}
else //no connection string name was provided
{
//get the default connection string
strReturn = ConfigurationManager.ConnectionStrings["YourConnectionName"].ConnectionString;
}
//return the connection string to the calling method
return strReturn;
}
}
}
Have you added a reference to System.Configuration.dll?
You have to add reference to System.Configuration.dll
When you right click and click on the Add reference button
Click .Net tab in the open popup
There you should be able to locate the System.Configuration.dll file
This is the path:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.dll
also you can add reference to the :System:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Configuration.Install.dll
(hope it helps :))
Which version of .NET Framework and Visual Studio are you using?
ConfigurationManager is only available in .NET 2 and above. If you are using .NET Framework 1.x and Visual Studio 2002/2003, you won't be able to use this class at all.
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx
Click "Other versions" link in the top of this page and you will see all versions it supports.
I ran into same issue using .Net Core, but using .NET Running Install-Package System.Configuration.ConfigurationManager in Package manager solved it for me.