- Home /
Connecting to Azure SQL db with Unity 4.0
Hi all, I need to connect to an Azure SQL database and write some stuff, this is what I've been trying to do:
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
...
public void saveToDB (string json)
{
string connectionString = "Server=tcp:wotsxsa994.database.windows.net,1433;" +
"Database=db;" +
"User ID=uid;" +
"Pwd=pwd;" +
"Encrypt=yes;";
SqlConnection dbcon = new SqlConnection (connectionString);
SqlCommand dbcmd = dbcon.CreateCommand ();
dbcmd.CommandType = CommandType.StoredProcedure;
dbcmd.CommandText = "INSERT INTO " + table + " VALUES (3, 433, 433, 1" + json + ")";
object result;
try
{
dbcon.Open ();
result = dbcmd.ExecuteScalar ();
Debug.Log (result);
dbcon.Close ();
}
catch (System.Exception ex)
{
Debug.Log (ex);
}
}
Any idea what I might be doing wrong? This is what I get:
NotImplementedException: SSL encryption for data sent between client and server is not implemented.
System.Data.SqlClient.SqlConnection.SetProperties (System.String name, System.String value)
System.Data.SqlClient.SqlConnection.SetConnectionString (System.String connectionString)
System.Data.SqlClient.SqlConnection.set_ConnectionString (System.String value)
(wrapper remoting-invoke-with-check) System.Data.SqlClient.SqlConnection:set_ConnectionString (string)
System.Data.SqlClient.SqlConnection..ctor (System.String connectionString)
(wrapper remoting-invoke-with-check) System.Data.SqlClient.SqlConnection:.ctor (string)
Comm.saveToDB (System.String json) (at Assets/[TB] Script/General/Comm.cs:649)
I guessed it had something to do with the "Encrypt = yes" in the connection string, so I tried removing it and now I get this:
Mono.Data.Tds.Protocol.TdsInternalException: Server closed the connection. ---> System.IO.IOException: Connection lost
at Mono.Data.Tds.Protocol.TdsComm.GetPhysicalPacketHeader () [0x00000] in <filename unknown>:0
at Mono.Data.Tds.Protocol.TdsComm.GetPhysicalPacket () [0x00000] in <filename unknown>:0
at Mono.Data.Tds.Protocol.TdsComm.GetByte () [0x00000] in <filename unknown>:0
at Mono.Data.Tds.Protocol.Tds.ProcessSubPacket () [0x00000] in <filename unknown>:0
at Mono.Data.Tds.Protocol.Tds.NextResult () [0x00000] in <filename unknown>:0
at Mono.Data.Tds.Protocol.Tds.SkipToEnd () [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Mono.Data.Tds.Protocol.Tds.SkipToEnd () [0x00000] in <filename unknown>:0
at Mono.Data.Tds.Protocol.Tds70.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x00000] in <filename unknown>:0
at Mono.Data.Tds.Protocol.Tds80.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x00000] in <filename unknown>:0
at System.Data.SqlClient.SqlConnection.Open () [0x00000] in <filename unknown>:0
UnityEngine.Debug:Log(Object)
Comm:saveToDB(String) (at Assets/[TB] Script/General/Comm.cs:664)
I'm seriously clueless, I've rarely worked with databases and this is the first time I have to deal with Azure, no idea if and how it may differ from other SQL Server dbs... Any help will be highly appreciated!
Answer by zandalus · Dec 10, 2012 at 07:11 PM
Have you tried adding "Trusted_Connection=True;" to the connection string? I don't know Azure very well but I think it only accepts encrypted connections, not sure how you can implement SSL connections in Unity though.
I tried that, nothing changed. I couldn't find anything about using SSL in Unity... Still lost.
Answer by BobbyDoogle · Oct 03, 2014 at 03:17 PM
Has the writer of this thread figured it out in all this time, I would like to do the same thing, cross platform.
Nope, sorry. We just switched to a WWWForm with POST data.
Your answer
![](https://koobas.hobune.stream/wayback/20220613085234im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Mono.Data.Sqlite.dll set password error 0 Answers
SqliteKit encrypt incorrectly 1 Answer
How to integrate with Google Cloud mysql 0 Answers
Cloud recognition in Vuforia 0 Answers
Backend as a Service (BaaS) with RDBMS / SQL and Unity integration 1 Answer