1 回答

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
Unity3d連接SQL Server數(shù)據(jù)庫(kù):
首先需要把Unity安裝路徑下的System.Data.dll和Mono.Data.SqliteClient.dll拷貝到當(dāng)前unity工程的Assets文件夾下,因?yàn)橹笤谀_本中引用的.dll并不是framework提供的。腳本的內(nèi)容:
using UnityEngine;
using System;
using System.Collections;
using System.Data;(這個(gè)必須是引用自u(píng)nity的安裝目錄下,如果找不到就搜索一下)
using System.Data.SqlClient;
public class ConnectSQL : MonoBehaviour
{
// Use this for initialization
void Start()
{
string connectionString = "Data Source=XYL-PC;DataBase=Unity;uid=sa;pwd=123456;";
SqlConnection con = new SqlConnection();
con.ConnectionString = connectionString;
con.Open();
if (con.State == ConnectionState.Open)
{
print("Connect success!");
}
else
{
print("Connect Failure!");
}
}
}
- 1 回答
- 0 關(guān)注
- 1265 瀏覽
添加回答
舉報(bào)