Quantcast
Channel: Questions in topic: "dll"
Viewing all articles
Browse latest Browse all 706

MSSQL Connection and Select

$
0
0
To enable MSSQL databases in your project you must copy/add System.Data.dll to your asset folder. You can find System.Data.dll here: `C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\unity` Once added, you must add it to your references inside MonoDevelop or Visual Studio. Add usings: using System.Data; using System.Data.SqlClient; Now you can connect to your database: private string _conString = @"Data Source = 127.0.0.1; user id = Username; password = Password; Initial Catalog = DatabaseName;"; public string SimpleQuery ( string _query ) { using (SqlConnection dbCon = new SqlConnection(_conString)) { SqlCommand cmd = new SqlCommand(_query, dbCon); try { dbCon.Open(); string _returnQuery = (string) cmd.ExecuteScalar(); return _returnQuery; } catch (SqlException _exception) { Debug.LogWarning(_exception.ToString()); return null; } } } Then you can use something like this. string _stringRequest = R_Database.SimpleQuery("SELECT TOP 1 ColumnName FROM TableName WHERE ColumnName2 = 'SomeValue'"); Hope this will help, took me a while to gather all the fragmented information. Not many use MSSQL databases, but in my situation it worked out for the best.

Viewing all articles
Browse latest Browse all 706

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>