当前位置:网站首页>Unity connect to Microsoft SQLSERVER database

Unity connect to Microsoft SQLSERVER database

2022-06-12 11:21:00 Game programming

1. To configure Unity Environmental Science

  1. Unity Editor Set up Unity Frame compatibility to 4.X In the editor , You need to open the player settings ( file -> Build settings -> Player settings ). then , Under other settings , You can find the runtime and API Level
    Unity Connect Microsoft SQLSERVER database - The first 1 Zhang

2. add to ddl

Unity Find the required... In the installation path ddl, Copy to project's Assets Under the folder D:\unity\2020.3.8f1c1\Editor\Data\MonoBleedingEdge\lib\mono\4.7-api

Unity Connect Microsoft SQLSERVER database - The first 2 Zhang

Copy to the project folder

Unity Connect Microsoft SQLSERVER database - The first 3 Zhang

2. Connection database scripting

  1. quote using System.Data.SqlClient; Namespace
  2. Write a script
  void Start()    {        SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();        builder.DataSource = "localhost";   // update me        builder.UserID = "sa";              // update me        builder.Password = "123456";      // update me        builder.InitialCatalog = "db_example";        string res = "";        try        {            using (SqlConnection connection = new SqlConnection(builder.ConnectionString))            {                connection.Open();                // READ demo                string sqlStr = "select * FROM [db_example].[dbo].[tb_user];";                using (SqlCommand command = new SqlCommand(sqlStr, connection))                {                    using (SqlDataReader reader = command.ExecuteReader())                    {                        while (reader.Read())                        {                            res = reader.GetInt32(0).ToString();                        }                    }                }            }        }        catch (SqlException e)        {            Debug.Log(e.ToString());        }        Debug.Log(res);    }

3. Configuration database

  1. Database security configuration allows remote connection with user name and password

  2. Login status settings

  3. Database services TCP/IP Service is open

  4. restart SQLSERVER service

author :alwaysOnCoding

Game programming , A game development favorite ~

If the picture is not displayed for a long time , Please use Chrome Kernel browser .

原网站

版权声明
本文为[Game programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206121111513999.html