将Unity与SQL Server连接

时间:2015-12-13 06:59:43

标签: android sql unity3d

每个人我都有问题连接到android类型手机中的sql server我会在windows application的代码工作的顶峰代码但是当我构建到android时它给出错误我需要并希望帮助我为解决这个问题谢谢你

当我构建到android apk时出现错误:

enter image description here

这是在windowns app中使用的代码:

#pragma strict
import System;
import System.Data;
import System.Data.SqlClient;
var dbcon : IDbConnection;
var connectionString : String;

function Start () {
    connectionString = "Server=dbdatabase.mssql.somee.com; Database=dbdatabase;User ID=dbdatabase_SQLLogin_1; Password=1j8uc1yyja"; 
}

function Update () {
}

var user :String="";
var pas :String="";
function OnGUI()
{
    GUI.Label(new Rect(150, 130, 100, 100), "Name :");
    GUI.Label(new Rect(150, 160, 120, 120), "Pass :");
    user = GUI.TextField(new Rect(200, 130, 100, 20), user);
    pas=GUI.TextField(new Rect(200,160,100,20),pas);

    if (GUI.Button(Rect(200,190,100,50),"Login"))
    {
        dbcon = new SqlConnection(connectionString);
        dbcon.Open();
        var dbcmd : IDbCommand = dbcon.CreateCommand();
        var cmdSql : String = "SELECT name FROM setting WHERE name='"+user+"' and pass='"+pas+"'";     
        dbcmd.CommandText = cmdSql;  
        var reader : IDataReader = dbcmd.ExecuteReader();

        while(reader .Read()) {
            var nm : String = reader ["name"].ToString();
           print ("OK "+nm);
        }

        reader .Close();
        reader = null;
        dbcon.Close();
        dbcon = null;
    }
}

0 个答案:

没有答案