System.Data.SQLite on macOS using C# ?
(1) By norm (npalardy) on 2022-10-08 14:46:07 [link] [source]
I'm just getting started with C# on macOS so be gentle here
I''ve added the NuGet package for System.Data.SQLite but it seems to only really be supported on Windows. Is this correct ?
Any chance that since C# on macOS is a thing now that there might be support for this on .Net core on macOS ?
(2) By mistachkin on 2022-10-08 20:30:35 in reply to 1 [link] [source]
There is a macOS interop assembly in the System.Data.SQLite.Core package; however, it is for x86.
(3) By norm (npalardy) on 2022-10-08 21:45:15 in reply to 2 [link] [source]
x86 is fine for me as I'm on a slightly older x86 machine
Now to figure out how to take advantage of the interop package :) Like I said - quite new to this :P
Thanks for the pointer !
(4) By norm (npalardy) on 2022-10-10 20:48:24 in reply to 2 [link] [source]
Is there something special I need to do to enable it for use it ? I added the Systemm.Data.SQLite package to my project. Put in a using clause and have declared a variable in my app to hold the SQLIteConnection. But when I run and get to the line that creates the connection
sqlite_conn = new SQLiteConnection("Data Source=:memory:");
I get an error (trimmed for the sake of brevity)
System.DllNotFoundException: SQLite.Interop.dll assembly:<unknown assembly> type:<unknown type> member:(null)
at at (wrapper managed-to-native) System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none(System.Data.SQLite.SQLiteConfigOpsEnum)
at System.Data.SQLite.SQLite3.StaticIsInitialized () [0x0001c] in <582c551e66394e5abdf6cabd080bc771>:0
at System.Data.SQLite.SQLiteLog.PrivateInitialize (System.String className) [0x00032] in <582c551e66394e5abdf6cabd080bc771>:0
at System.Data.SQLite.SQLiteLog.Initialize (System.String className) [0x00023] in <582c551e66394e5abdf6cabd080bc771>:0
at System.Data.SQLite.SQLiteConnection..ctor (System.String connectionString, System.Boolean parseViaFramework) [0x0002c] in <582c551e66394e5abdf6cabd080bc771>:0
at System.Data.SQLite.SQLiteConnection..ctor (System.String connectionString) [0x00000] in <582c551e66394e5abdf6cabd080bc771>:0
at at (wrapper remoting-invoke-with-check) System.Data.SQLite.SQLiteConnection..ctor(string)
I'm truly at a loss as to how to fix this or what I might need to do to make this work
Any help would be amazing ! Thanks
(5) By mistachkin on 2022-10-11 02:03:14 in reply to 4 [link] [source]
Do you have a "SQLite.Interop.dll" file in your application directory?
What SQLite related DLLs do you have in your build output directory?
(6) By norm (npalardy) on 2022-10-11 23:18:51 in reply to 5 [link] [source]
There does not appear to be SQLite.Interop.dll in the build app directory Where should that come from ?
I used the NuGet package for System.Data.SQLite 1.0.116 (dated 2022-06-01) That also had required several dependencies like EntityFramework, etc
Other SQLIte DLL's are
System.Data.SQLite.EF6.dll
System.Data.SQLite.dll
System.Data.SQLite.xml
But no Interop :(
Is there something I need to do / enable / set to make sure it gets excited alongside the built application ?
(7) By mistachkin on 2022-10-13 00:34:27 in reply to 6 [source]
It should be copied from the NuGet package directory "runtimes\osx-x64\native" within the project directory. Do you see one there?
(8) By norm (npalardy) on 2022-10-13 05:50:41 in reply to 7 [link] [source]
I do I've copied it next to the built executables for builds of the project and debug runs And been trying many of the FAQ's as well although there are some I'm not sure where to set those things in VS on macOS So far no success :(
(9.1) By norm (npalardy) on 2022-10-13 23:05:49 edited from 9.0 in reply to 7 [link] [source]
Some success (YAY !)
I completely reinstalled VS for macOS
Started a brand new Console application
Added the System.Data.SQLite nuget package
Add about 5 lines of code to insert the using statement, an instantiate a SQLiteConnection and debugged
And it all worked
I did nothing and the interop dll is copied
So now to figure out how to make my other project do the same
Thanks for your patience & replies
(10.1) By Chris Locke (chrisjlocke1) on 2022-10-13 17:21:59 edited from 10.0 in reply to 9.0 [link] [source]
I don't have a mac so have zero knowledge, but do use VS on Windows.
I don't use the nuget packages, but download the three files and add them to the same directory (sort of) as my .exe
Appreciate the files will be different, but have you followed the layout as per the download page on system.sqlite.data.org? You just need the interop.dll and two copies of the system.sqlite.data.dll - 32 and 64bit versions. These are the Windows 'rules' - don't know if the mac version is similar - happy to experiment with you and tinker.
(11) By norm (npalardy) on 2022-10-13 22:52:03 in reply to 10.1 [link] [source]
Thanks for the ideas I'm going to see if my main project I can get working now since I see it CAN work
One thing I will say is that VS on macOS is NOT what you're used to as VS on Windows
Capabilities are quite different
Its still a prerelease and evolving - slowly but steadily
(12) By norm (npalardy) on 2022-10-13 23:38:40 in reply to 10.1 [link] [source]
Honestly not sure what I'm doing, or not doing, right
I think I have set things up right as you noted by having the interop.dll in the x64 directory next to the built app
I still get the same error I originally reported
Yet my simple console app worked without any futzing about at all
And just for fun I converted my sample app to using PostgreSQL in about 2 minutes by downloading the nuget package and adjusting my code ever so slightly
I'll grab the package you mentioned and see if having both the x86 and x64 interop dlls works
(13) By Chris Locke (chrisjlocke1) on 2022-10-14 06:15:46 in reply to 12 [link] [source]
When developing in Windows, VS prefers the 32-bit. Might just be the default settings. Again, appreciate that's Windows, so different fish of kettles.
(14) By norm (npalardy) on 2022-10-14 23:15:22 in reply to 13 [link] [source]
Pretty confident saying that this is 64 bit as macOS hasn't supported running 32 bit code for several releases now.
Apples been pretty aggressive about moving devs to writing 64 bit only code for some time