SQL Server with Unity3D - c#

I want to use SQL Server with Unity. I add System.Data.dll to assets in Unity project but I get this error:
The type or namespace name 'SqlClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
Then I added sqlclient.dll to the assets folder, but I still get:
The type name 'SqlConnection' could not be found in the namespace 'System.Data.SqlClient'. This type has been forwarded to assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Consider adding a reference to that assembly.
Please help me! What's wrong?

After some researches, looks like there are much easy way to import sql in new versions of Unity:
Download new System.Data.SqlClient from nuget. For example, use in
terminal nuget install System.Data.SqlClient -Version 4.7.0
-OutputDirectory <some temp dir>
Open unity build settings, find Api Compatibility Level. It will be .NET 4.x or .NET Standard 2.0
Create Plugins directory in folder
Copy dll from <some temp dir>/lib/<api level>/System.Data.SqlClient.dll to Plugins directory.
That all, you can use sql :)
For example, in my case there are .NET Standard 2.0 compat. level and <some temp dir>/lib/netstandard2.0/System.Data.SqlClient.dll library.

Related

The type or namespace name 'Optimization' does not exist in the namespace

I am running into an issue where The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' when it was already installed(I checked Nuget Package Manager)
What I have tried:
1: Directly copy dll to the Bin folder because I notice it was missing. This did not work.
2: Uninstall and re-install it from Nuget Package Manager, after that, the same error still exist. On top of that, I got a new error
The pre-application start initialization method Start on type
System.Web.Optimization.PreApplicationStartCode threw an exception
with the following error message: Could not load file or assembly
'Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The
system cannot find the file specified..
Package Version: 1.1.3
It is a WebForm Project, not MVC(there are many posts have solutions that's unique to MVC, so it is not applicable in my case)
I have installed both packages with the highest stable version, so I am not sure why Infrastructure is yelling at me.
I have fortunately found the solution:
Web.Optimization requires Web.Infrastructure. When I reinstall Web.Optimization, it changed the targetFramework from 40 to 45, while Infrastructure is looking at 40. Also, despite the fact that I have infrastructure installed, the dll is also missing. I copied net40 version of dll for both Web.Optimization and Web.Infrastructure and then it worked.

The type or namespace name 'OpenIdConnect' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?)

I have added a Microsoft.Owin.Security.OpenIdConnect.dll externally(tried both methods using Package Manager Console and using add reference ) to my ASP.NET MVC Application, but still get the same error.
The type or namespace name 'OpenIdConnect' does not exist in the namespace 'Microsoft.Owin.Security' (are you missing an assembly reference?)
I have attached AccountController.cs, packages.config and references
Any help.
You can try with deleting Package folder from source directory (Location: .sln file), then try to resotre packages.
Steps to restore nuget packages:
Right click on solution file.
Select Nuget restore NuGet Package option
I found the solution from Microsoft site
https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2012/0e92xd7b(v=vs.110)
Possible causes for this error include the following:
An assembly that contains the definition of a type was not referenced in the compilation; use /reference (Import Metadata) to specify the assembly
You passed a variable name to the typeof operator.
You tried to reference an assembly that is not part of your target .NET Framework profile. For more information, see Troubleshooting .NET Framework Targeting Errors.
In my case, the issue is that an assembly that is not part of my target .NET Framework profile.

I am trying to use SPMETAL generated model classes with Sharepoint 2016, getting errors on Microsoft.Sharepoint.Linq

After running SPMETAL.exe against my Sharepoint 2016 site, I imported the generated model to my project. I get 263 errors of the type "The type or namespace name 'Linq' does not exist in the namespace 'Microsoft.Sharepoint' (are you missing an assembly reference?).
By the way, in order to generate a datacontext model from your Sharepoint site for use with Linq to SQL with SPMETAL.exe, here's the command:
"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\BIN\SPMETAL.exe" /web: /namespace: /code:
Change the "16" above, depending on the version of Sharepoint you have / which folder you have there.
I have already referenced Microsoft.SharePoint.dll and installed the client and client runtime using Nuget.
Did something major change and can I still use SPMETAL? I've done a ton of searches, but other namespaces with Linq show up and I still haven't found what assembly or package Microsoft.Sharepoint.Linq resides in.
After Googling quite a bit, I found a reference to the assembly the Microsoft.Sharepoint.Linq namespace is located within:
"Microsoft.Sharepoint.Linq.dll". I did a file search for that and found it in the .NET install, assemblies subfolder:
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SharePoint.Linq\v4.0_16.0.0.0__71e9bce111e9429c\
I included a reference to that in my project and all the errors went away.

System.Data.SQLite.dll isn't found trying to add a reference

(Beginner level)
I have a DB in SQLite3.
I would like to populate a DataGridView by data from the DB.
Currently I'm at the first phase to create a connection/using.
Also, when I add this: using System.Data.SQLite; I get an error:
Error CS0234 The type or namespace name 'SQLite' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
In this tutorial it guides to add System.Data.SQLite.dll as reference - in folder Program Files (x86) should appear System.Data.Sqlite, but the folder does not exist. The dll file cannot be found, I searched for it also in the Reference Manager Browse.
(Thanks in advance)
First Add With Nuget Syste.Data.SqLite.
or run the command in the Package Manager Console
Install-Package System.Data.SQLite
Then right click on your project references, an select add reference.
Select Under Assemblies, Framework.
Then left click on System.Data.SQLite.
This will add Mono.Data.SqLite to your reference.
So type in your code
using Mono.Data.Sqlite;
This reference is of the same use case as System.Data.SQLite.
You can add the assembly with NuGet. Install System.Data.SQLite.
To install System.Data.SQLite (x86/x64), run the following command in the Package Manager Console
Install-Package System.Data.SQLite

How to reference System.Threading.Tasks, MySql and MysqlConnection with Mono

I am trying to run a C# console application on my server which is running Ubuntu Server 12.04. I have installed Mono JIT version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2) and additional packages like gmcs and MonoDevelop. The file that I am trying to execute is called Program.cs and when I run the command $gmcs Program.cs I get the following errors:
error CS0234: The type or namspace name 'Tasks' does not exist in the namespace 'system.Threading'. Are you missing assembly reference?
error CS0246: The type or namespace name 'MySql' could not be found. Are you missing a using directive or an assembly reference?
error CS0246: The type or namespace name 'MySqlConnection' could not be found. Are you missing a using directive or an assembly reference?
I have researched into referencing the .dll files for the above namespaces but have not been able to find an answer that is clear. Most forum links suggest that I install mono - trunk, but I want to know if I should uninstall the existing mono package and then install mono-trunk.
I am new to the Unix platform and researching every step of my way. Your help will be much appreciated.
If you are compiling from the command line, you will need to pass the referenced assemblies as a series of /r or /pkg switches, such as:
mcs /r:MySql.Data.dll Program.cs
Obviously you will need to have the required assemblies installed too.
Also note that gmcs is an (old) alias for the .net 2.0 compiler, that's why it doesn't see System.Threading.Tasks (which is a .net 4 feature). See the -sdk switch of mcs.
You should probably install monodevelop to have a user-friendly IDE to help you.

Categories