FileNotFoundException when connecting to Postgres database - c#

I am getting a fileNotFoundException when I try to connect to my postgres database.
Her is a sample of the code.
connectionString = "Server=127.0.0.1;Port=5432;Database=MMEData;User Id=postgres;Password=nH9Ummg5;";
dbConn = new NpgsqlConnection(connectionString); //This constructor is when I get the exception
Here is the exception I am getting:
{"File or assembly name Mono.Security, or one of its dependencies, was not
found. Mono.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"}
I copied the npsql.dll file to the application's directory and afterwards made a reference to it.
I also copied the rest of the files from a zip called 'Npgsql-2.2.0-net45.zip'.
I have the using npgsql; statement.
I am running pgAdmin III at the same time and in it I connected the server. The Database name is MMEData.
I am running application and postgres on the same (local) machine and on the default port (5432).
Anyone any idea what I am missing?

Please add reference name called Mono.Security dll in your project solution it could be avoid this type of errors

you need to copy the library Mono.Security.dll to the application's directory and afterwards made a reference to it.

I have had the same problem and my solution was to add Mono.security.dll as a reference to my project, after that the connection to PostgreSQL database was fine.
I downloaded the nuget package.
I renamed it as a zip file.
I extracted Mono.security.dll to my project.
I added it as a reference with always copy to directory.
I compiled my project and runned it and it was ok.

Related

Dependency change results in missing reference to the old file

It happened I am responsible for maintaining an older C# application. The application connects to a MySQL server and for some reason the MySql.Data.dll was included on disk and checked in.
So I thought on changing this to reference using a NuGET package. I removed the dependency on the checked in binary and added a package reference.
Now when I build the application I get the following error:
"path\myproject.csproj" (build target) (1) ->
(GenerateApplicationManifest target) ->
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(3987,5): error MSB3113: Could not find file 'lib\MySql.Data.dll'.
I tried to find any occurrence of that dll but there seems to be no reference anymore.
How to stop the project referencing the non existing library?
The problem was, that even though I removed the dll within Rider the deployment reference (<Content ...) within the csproj file was not removed.

Desktop application + SQLite - Version=1.0.65.0 vs. Version 1.0.104.0

I am currently writing a desktop application (nothing hosted in IIS or similar, .NET 4.5.2) which makes use of SQLite and the Entity Provider for SQLite. For this to get it to work in Visual Studio, I had to install the 1.0.65.0 version package from the SQLite site to get the EF6 provider for SQLite inside Visual Studio. This worked as expected ad as far as I understood, this is also the only way this can be done.
For my application, I would like to use the current version which is 1.0.104.0 (again, info from the sqlite page). I have successfully added the Nuget package for this version to my application and when I look into the references tab, I can see System.Data.SQLite, System.Data.SQLite.EF6 and System.Data.SQLite.Linq, all with the version 1.0.104.0 and Specific Version set to True. Copy Local is set to true for all three of them.
So now when I run my application and get to the line:
using (var ctx = new SmtAoiLookupEntities())
{
foreach (var lu in ctx.Lookups.Where(d=>!string.IsNullOrEmpty(d.Aoi)))
{
...
}
}
I get the following error message:
An exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll and wasn't handled before a managed/native boundary
Additional information: Could not load file or assembly 'System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
From this, I understand that my application tries to load version 1.0.65.0, although all my references point to 1.0.104.0. I have absolutely no idea where my application gets the idea that I want to load 1.0.65.0. I even did a find in files to catch any reference to "1.0.65" with absolutely no results.
I used
gacutil -l System.Data.SQLite
to see which Assemblies are stored in the GAC -> Version 1.0.104.0
Now, this appears only to happen when I run the application from within Visual Studio; If I run the application outside Visual Studio as an executable I get a different error when saving the context. It appears that this is an application error and not related to the assembly version problem. I have also tried setting the application to a 32bit application, the issue stays the same.
The main issue: I would like to be able to debug the application inside Visual Studio, otherwise this could become quite cumbersome. Any ideas how I tell Visual Studio not to load the 1.0.65.0 libs?
A project in your solution is still pointing to previous SQLite version. In my case it was the project which file was throwing the error. Making sure every project in the solution has the updated package version solved the problem for me.

VS2012EXPRESS Ado.Net SQLite missing DLL issue

I'm trying to work out how to use ADO.Net Sqlite in VS2012 Express with no luck.
Things im doing from begining:
Starting new project and installing "System.Data.SQLite (x86/x64)" via NuGet for solution.
Adding using System.Data.SQLite; to directives.
Writing simple code like:
SQLiteConnection sql_sck = new SQLiteConnection("Data Source=test.sqlite;Version=3;New=False;Compress=True;");
Everything seems to look okay, VS recognize class names and changes their colors. However after running the program, in the sql_sck... line, exception is raised - about missing dll ?
An unhandled exception of type 'System.DllNotFoundException' occurred in System.Data.SQLite.dll
Additional information: Could not load DLL 'SQLite.Interop.dll': Could not find specified module. (Exception HRESULT: 0x8007007E)
Any ideas how can I make this work ? Is there anything I've done wrong / any steps missing ?
Somewhere Visual Studio will have created SQLite.Interop.DLL. You need to find that DLL and copy it to the same directory as your application's executable.
I usually add Interop DLLs to my project as a reference and flag them for copying to the output directory in order to ensure that others that use the projects don't forget the manual step.

Could not load System.Data.SqlServerCe.Entity.dll (Yet it's there)

I have a silverlight application. The server app has an SQL Server CE 4 .sdf in App_Data, and an ADO.NET model generated from it.
If I try to Add->New Item->Domain Service Class, I get the error:
Schema specified is not valid. Errors:
Models.TasksDatabaseMode.ssdl(2,98): error (0004): Could not load
System.Data.SqlServerCe.Entity.dll. Reinstall SQL Server Compact.
However, I installed RIAServices.EntityFramework and EntityFramework.SqlServerCompact via NuGet, which has successfully downloaded this .dll to /packages, and the file has been copied out into the /bin folder. So I have no idea where it is apparently looking for this .dll, if not there.
Perhaps related, I was earlier attempting to have the database generated code-first. However, the Domain Context Wizard was also failing, but with an error about an index being out of bounds. With a manually written service, the build was failing with a MetadataWorkspace error, about which I couldn't find any information.
Does installing the runtime directly (http://www.microsoft.com/en-us/download/details.aspx?id=17876) fix the issue?
Also, what version of the binary are you using? I suspect that you may have the private version (4.0.0.1) and generation is expecting the machine version (4.0.0.0)

Problem regarding c#.net application communication with MySql

I am Developing a Desktop Application with c# .net and MySql as Database. It's an encryption application which produces an exe file which communicates with MySql to bring some data. I am using the MySql.Data.dll for application communication with MySql. When it produces exe there is no MySql.data.dll with it so it throws an error:
Could not load file or assembly 'MySql.Data, Version=6.2.2.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
Set the Copy Local Attribute of the assembly reference ( MySql.Data.dll ) to true. That makes the reference copy itself to the output directory.
You need to copy the MySql.Data.dll into the same directory where your application will execute. E.g. the runtime folder.
In other words: At some point you had to locate the MySql.Data.dll to use it in your project's client code. Simply find it again and copy it to the runtime folder: /bin/debug for example
You need to do as psasik stated. If you are to redistribute the application then you need to add the dll to the setup project and you can always use an MSBuild task to copy the dll during debugging (or just leave it in the bin\Debug directory)

Categories

Resources