How do I import MySql Connector into Unity Project?

无人久伴 提交于 2020-01-14 03:28:28

问题


  • I've tried placing the basic dll's into unity's assets folder - Result: "blah blah will cause Unity to Crash Error."
  • I've tried Manually adding references - Result: Unity refreshes its references anytime the editor refreshes, so worthless.
  • I've tried Installing using NuGet - Result: Closest to success as it handles all the dependencies and whatnot but I get: Assets/Scripts/Developing/TalkToDB.cs(3,7): error CS0246: The type or namespace name `MySql' could not be found. Are you missing an assembly reference?

Is it some kind of a combination of "Use NuGet then copy the dll into the Assets?" or something redundant like that? cause that's about the best guess I've got.


Also, I've tried a couple older versions of the NuGet package to no avail. As well, MySql.Data is listed under the References of "Assembly-CSharp" And my Unity is set to 4.X framework Using Unity's latest 2018.2.5f1 (64bit) (I really hope that I don't have to ditch 4.x for this to work... I'll miss initializing values to properties..)


回答1:


Fortunately I came across this:

How to get MySql Connector/Net Working with Unity 2017

And Regarding Security concerns. My Key is none of my sessions should ever be persistent from .NET - There will be advanced PHP scripts for altering of data and anything regarding elevated permissions.

Reference: Why you shouldn’t connect your mobile application to a database

Beyond this,

Exceptions to the rule.

"Some database vendors may have provided drivers to connect to remote databases, but as yet I’m not aware of any.

Other exceptions include ODBC connectivity. For example, I’ve heard of developers being able to (or at least trying to) connect to MySQL databases using JDBC when developing applications in Java. This is not actually quite the same as connecting directly using a binary driver, however, it comes close..." - 2

This is exactly what I will be doing, using the MySql Connector to talk to MySql drivers (which I'm too tired at the moment to recall the name of(maybe it's based on ODBC? I can't remember. Thus Google. Lol))

So all in all, using the link provided at the top, Unity 2018 can be compatible with the latest (as of this post) MySql Connector(s).

Any Assets folder must contain: System.Data.dll & MySql.Data.dll (that's it)

No NuGet required.

However the error message: "Loading script assembly 'Assets/Plugins/MySql/System.Data.dll' failed!" And as of yet, it is apparently not able to reference connectionString from an app.config like your normal C# outside of Unity would be able to. This being said, I'm working on finding either Unity's implementation of the app.config, or an equivalent alternative.


UPDATE:

Aside from a couple annoying dll loading errors in Unity that don't influence anything - other than annoying me and wasting a couple bytes of RAM for a second (lol, y'kno.); All works well and I remember the reason I am not concerned about connecting my application directly to my Database is because the ONLY permissions the users will have is the Execute permission so all procedures will be stored on the server (via Stored Procedures) and thus protecting the database against any potential attacks even if cough coughwhencough ahem, a user decides to "de-compile" (is that even a word...? heh) my application.


Final Update:

As I posted here;

It took me a week to finally figure it out...

You need to use:

I18N.dll
I18N.West.dll
I18N.*.dll (Optional, they are region specific)
System.Data.dll

from C:\Program Files\Unity\Editor\Data\Mono\lib\mono\2.0

NOT the BleedingEdge path. Then it will work without errors [And in Builds]... confirmed in the latest Unity 2018.2.14f1 Place into the Assets folder - Also the project needs to be set to .Net 4.0



来源:https://stackoverflow.com/questions/52050951/how-do-i-import-mysql-connector-into-unity-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!