简体   繁体   中英

How to connect SQL Server Database with Unity3D?

My English is not good but I'm trying my best to describe my problems. I have copied I18N.dll, I18N.CJK.dll, I18N.West.dll and System.Data.dll from

D:\\Program Files\\Unity\\Editor\\Data\\Mono\\lib\\mono\\2.0 ,

but soon an error occurred as follows:

error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\\GSS Project\\Assets\\Plugins\\System.Data.dll' and 'D:\\Program Files\\Unity\\Editor\\Data\\MonoBleedingEdge\\lib\\mono\\4.7.1-api\\System.Data.dll'. Remove one of the duplicate references.

And also, the same Exception occurred in the other directory:

D:\\Program Files\\Unity\\Editor\\Data\\NetStandard\\compat\\2.0.0\\shims\\netfx\\

At that time, in order to solve the problem, I removed the System.Data.dll in both two directories and then I can use the namespace System.Data in the Visual Studio 2017. But when I use System.Data.ConnectionState , there is an another error:

Assets\\Scripts\\DBConnection.cs(39,35): error CS0433: The type 'ConnectionState' exists in both 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

After many methods were tried, I found if I entered

Edit --> Project Settings --> Player --> Other Settings --> Configuration --> Api Compatibility Level

and turned .Net Standard 2.0 to .Net 4.x, the error could be avoid. But is this method right? After doing this I still can't access the database because many Exceptions occurred(Most of them are about SqlConnection ).

There might be many problems in my method, but can anyone please tell me what the right method is?

Thanks very much.

As the user in the comments stated , direct connection with the use of dll is no more secure and its safer and better to use php interconnection.

(Especially if you are thinking of publishing on WEBGL platform you will have difficulties to make the sql connection work after you build the game , thats where i am stuck at the moment)

With that said ,

You get this exception because of the

"system. .. "

which exists twice , you do not need the system.Data.dll in your assets.

Erase System.Data.dll , you only need the I18N files as you already have and the

MYSQL.data.dll , GoogleProtofub and bouncyCasteCrypto.

Also change the NET version back to 4X.V2.

Lastly , you can find the mysql connector/NET files from MYSQL official site.

I hope this helps. Let me know for any other error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM