C# 当尝试打开与phpmyadmin服务器的连接时,程序冻结

C# 当尝试打开与phpmyadmin服务器的连接时,程序冻结,c#,database,database-connection,C#,Database,Database Connection,我正在尝试让我的应用程序与phpmyadmin sql server中联机的数据库一起工作。当我启动应用程序时,它需要从数据库中获取密码,但当它试图打开连接时,整个程序就会冻结,并长时间保持这种状态。在我使用它的每一个类中,我都建立了一个新的连接,我不知道这是否是一个问题 下面是我用于此目的的数据库类 类数据库 { 专用SqlConnection; 私有字符串connectionstring=“Server=studmysql01.fhict.local;Uid=dbi413434;Databa

我正在尝试让我的应用程序与phpmyadmin sql server中联机的数据库一起工作。当我启动应用程序时,它需要从数据库中获取密码,但当它试图打开连接时,整个程序就会冻结,并长时间保持这种状态。在我使用它的每一个类中,我都建立了一个新的连接,我不知道这是否是一个问题

下面是我用于此目的的数据库类

类数据库
{
专用SqlConnection;
私有字符串connectionstring=“Server=studmysql01.fhict.local;Uid=dbi413434;Database=dbi413434;Pwd=Koekjesdeeg;”;
私有字符串nfcId;
私家车;
私人国际研究所;
公共数据库()
{
连接=新的SqlConnection(connectionstring);
}
公共字符串GetPassword(字符串用户名)
{
connection.Open();
SqlCommand cmd=newsqlcommand(“从登录名中选择密码,其中username='”+username+'”,连接);
字符串checkPassWord=Convert.ToString(cmd.ExecuteScalar());
connection.Close();
返回checkPassWord;
}
公共void MakeCount(字符串用户名、字符串密码)
{
connection.Open();
SqlCommand comm=connection.CreateCommand();
comm.CommandText=“插入登录(用户名、密码)值(@USERNAME、@PASSWORD)”;
comm.Parameters.AddWithValue(“@USERNAME”,USERNAME);
comm.Parameters.AddWithValue(“@PASSWORD”,PASSWORD);
if(comm.ExecuteNonQuery()==0)
{
抛出新的异常(“未创建帐户”);
}
connection.Close();
}
公共作废更改信息(双倍费率、整数最大停留时间、整数行、整数行)
{
字符串命令;
connection.Open();
SqlCommand comm=connection.CreateCommand();
如果(比率==0)
{
command=“UPDATE General SET Maximum_Stay=@Maximum_Stay,Row=@Row,Line=@Line,其中ID=1”;
}
否则如果(最大停留时间==0)
{
command=“更新常规设置速率=@Rate,Row=@Row,Line=@Line,其中ID=1”;
}
else if(行==0)
{
command=“更新常规设置速率=@Rate,Maximum_Stay=@Maximum_Stay,Line=@Line,其中ID=1”;
}
else if(行==0)
{
command=“更新常规设置速率=@Rate,Maximum_Stay=@Maximum_Stay,Row=@Row,其中ID=1”;
}
其他的
{
command=“更新常规设置速率=@Rate,Maximum_Stay=@Maximum_Stay,Row=@Row,Line=@Line,其中ID=1”;
}
comm.CommandText=命令;
comm.Parameters.AddWithValue(“@rate”,rate);
comm.Parameters.AddWithValue(“@maximum_stay”,maximum_stay);
comm.Parameters.AddWithValue(“@row”,row);
comm.Parameters.AddWithValue(“@line”,第行);
if(comm.ExecuteNonQuery()==0)
{
抛出新ArgumentException(“信息一般不更新”);
}
connection.Close();
}
public void CheckForId(整数id、整数行、整数行、bool take、字符串目标)
{
string queryUpdate=“更新事件日志集Rij=@row,Vak=@line,Beschikbaarheid=@take,Parkeerdoel=@target,其中ID=@ID”;
字符串queryInsert=“插入事件日志(ID、Rij、Vak、Beschikbaarheid、Parkeerdoel)值(@ID、@row、@line、@take、@target)”;
string queryDelete=“从事件日志中删除*,其中id=@id”;
connection.Open();
SqlCommand cmd=newsqlcommand(“从事件日志中选择id,其中id=@id”,连接);
cmd.Parameters.AddWithValue(“@id”,id);
字符串数据=Convert.ToString(cmd.ExecuteScalar());
SqlCommand comm=connection.CreateCommand();
如果(数据==“”)
{
comm.CommandText=queryInsert;
}
else if(Int32.Parse(data)==id)
{
comm.CommandText=queryUpdate;
}
其他的
{
comm.CommandText=queryDelete;
}
comm.Parameters.AddWithValue(“@row”,row);
comm.Parameters.AddWithValue(“@line”,第行);
comm.Parameters.AddWithValue(“@take”,take);
comm.Parameters.AddWithValue(“@target”,target);
comm.Parameters.AddWithValue(“@id”,id);
if(comm.ExecuteNonQuery()==0)
{
抛出新ArgumentException(“信息未正确插入checkForid”);
}
connection.Close();
}
公共双速率()
{
connection.Open();
SqlCommand cmd=newsqlcommand(“从常规中选择速率,其中ID=1”,连接);
双速率=Convert.ToDouble(cmd.ExecuteScalar());
connection.Close();
回报率;
}
public void SetId(int id、字符串nfcId、字符串kenteken、int行、int行、DateTime begintTijd)
{
如果(行!=-1 | |行!=-1)
{
connection.Open();
SqlCommand comm=connection.CreateCommand();
comm.CommandText=“插入INCHECK(Timestamp,NfcId,Kenteken,ParkeerRij,ParkeerVak)值(@Timestamp,@NfcId,@Kenteken,@ParkeerRij,@ParkeerVak)”;
comm.Parameters.AddWithValue(“@Timestamp”,BegintIjd);
comm.Parameters.AddWithValue(“@NfcId”,NfcId);
comm.Parameters.AddWithValue(“@Kenteken”,Kenteken);
comm.Parameters.AddWithValue(“@ParkeerRij”,第行);
通信参数