Unity3d connection to SQL Server database

Source: Internet
Author: User
Tags i18n

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);

}

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.