Before you write your code, you need:
1. The introduction of the Assembly System.Data.dll, located in C:Program filesunityeditordatamonolibmonounity (I unity by default installed in C disk).
2. Copy the System.Data.dll file to the current Unity project file under the Assets folder.
Although it can be run within unity but is not connected to the Web or EXE, it requires three additional DLL files I18n.dll,i18n.west.dll,i18n.cjk.dll, three files and System.data.dll In the same directory, to put the 4 DLL file together under the assets file to the final release can also be connected to the database.
public class Connectionsqlserver:monobehaviour
{
void Start ()
{
Connection string
SqlConnection connstr = new SqlConnection ("Data source=.;i Nitial catalog=exam;uid=sa;pwd=123 ");
SqlCommand cmd = new SqlCommand ();
Cmd. Connection = ConnStr;
Cmd.commandtype = System.Data.CommandType.Text;
Set up SQL connection statements
Cmd.commandtext = "SELECT * from Users";
SqlDataAdapter SDA = new SqlDataAdapter (cmd);
Sda. SelectCommand.Connection.Open ();
String strtemp = SDA. Selectcommand.executescalar (). ToString ();
Sda. SelectCommand.Connection.Close ();
Print ("Connect database Successful!" + strtemp);
}
}