Question by
virus4297 · Dec 28, 2020 at 11:25 AM ·
databaseconnectionsql
Not able to connect MS SQL to WebGL Program.
SocketException: An existing connection was forcibly closed by the remote host. I get this error when, I created an empty object "DBConnection" and attached the script DBConnection.cs to it. The function "connectDB()" is called on a button click later.
/***DBConnection.cs***/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using UnityEngine.UI;
using TMPro;
public class DBConnection : MonoBehaviour
{
public TMP_Text DBConnectionStatusText;
public void connectDB()
{
string connectionString = null;
connectionString = @"Data Source=VIRUSLAPPY\SQLEXPRESS;Initial Catalog=OccupancyUat;Integrated Security=SSPI;";
SqlConnection cnn = new SqlConnection(connectionString);
try
{
cnn.Open();
DBConnectionStatusText.text="Connected!!";
cnn.Close();
}
catch (Exception ex)
{
DBConnectionStatusText.text="Error Connecting!!"+ex;
Debug.LogException(ex, this);
}
}
}
I know this might not be the safe way to connect but couldn't find any material or source with an elaborated explanation of the alternate ways.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613022300im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Security with android 1 Answer
Unity Android database 0 Answers
issues with SQLITE DB, Getting the next data in the same column? 0 Answers
MSSQL 2014 Connection and Socket Exception 1 Answer
PHP & SQL on Android 0 Answers