为啥只允许我给30分??服务器:win2000,数据库SQL2000,平台VS2010,开发软件C#开发的winform的C/S局域网软件
在服务器建立了一个虚拟站点组建了一个webservice,单机调试没出过问题,局域网访问人少时也没出现问题,但是要是同时多人访问时,就会出现访问数据库混乱的情况,导致局域网所有使用该软件的全部瘫痪,一旦出现问题后无法解决,重启服务器有时也没效果,大概过1个小时后又恢复,请高手指点,问题在哪里,是IIS访问超限的原因还是代码有问题:
webservice代码如下:
namespace WebServer
{
/// <summary>
/// DBLib 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class DBLib : System.Web.Services.WebService
{
private static SqlConnection SqlCon { get; set; }
private static string _SqlConStr;
private static string SqlConStr
{
get
{
if (string.IsNullOrEmpty(_SqlConStr) )
_SqlConStr= ConfigurationManager.AppSettings["ConnectionString"];
return _SqlConStr;
}
}
private bool GetCon()
{
//if (SqlCon != null)
// return true;
try
{
SqlCon = new SqlConnection(SqlConStr);
SqlCon.Open();
return true;
}
catch (Exception ex)
{
SqlCon = null;
throw ex;
}
}
[WebMethod]
public DataSet GetData(string Sql, out string ExceptionStr)
{
try
{
ExceptionStr = null;
if (!GetCon())
return null;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds.Tables.Add(dt);
try
{
SqlCommand Command = new SqlCommand(Sql, SqlCon);
SqlDataAdapter adapter = new SqlDataAdapter(Command);
adapter.Fill(dt);
//SqlCon.Close();
return ds;
}
catch (Exception ex)
{
ExceptionStr = ex.Message;
SqlCon.Close();
return null;
}
}
finally
{
SqlCon.Close();
}
}
[WebMethod]
public string ExecSql(string Sql, out string ExceptionStr)
{
try
{
ExceptionStr = null;
if (!GetCon())
return "连接" + "数据库失败";
try
{
SqlCommand Command = new SqlCommand(Sql, SqlCon);
Command.ExecuteNonQuery();
//SqlCon.Close();
return null;
}
catch (Exception ex)
{
ExceptionStr = ex.Message;
SqlCon.Close();
return "执行Sql语句失败,失败原因:" + ex.Message;
}
}
finally
{
SqlCon.Close();
}
}
}
winform部分代码:
public static DataTable GetData(string Sql)
{
DataTable dt = new DataTable();
string Exceptionstr = "";
var _dblib = dblib;
//跟踪到这一步是SQlL的查询字符串是正确的,但是不能再继续跟踪到服务器了
DataSet ds = _dblib.GetData(Sql, out Exceptionstr);
//但是返回的ds值就不是要查询的结果了,很是无助呀
if (ds != null)
{
return ds.Tables[0];
}
MessageBox.Show(Exceptionstr);
return null;
}
public static string ExecSql(string Sql)
{
string Exceptionstr = "";
string falg = "";
var _dblib = dblib;
falg = _dblib.ExecSql(Sql, out Exceptionstr);
if (falg != null)
{
MessageBox.Show(Exceptionstr);
return Exceptionstr;
}
else
{
return null;
}
}
跪求大侠们指点指点,谢谢
在服务器建立了一个虚拟站点组建了一个webservice,单机调试没出过问题,局域网访问人少时也没出现问题,但是要是同时多人访问时,就会出现访问数据库混乱的情况,导致局域网所有使用该软件的全部瘫痪,一旦出现问题后无法解决,重启服务器有时也没效果,大概过1个小时后又恢复,请高手指点,问题在哪里,是IIS访问超限的原因还是代码有问题:
webservice代码如下:
namespace WebServer
{
/// <summary>
/// DBLib 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class DBLib : System.Web.Services.WebService
{
private static SqlConnection SqlCon { get; set; }
private static string _SqlConStr;
private static string SqlConStr
{
get
{
if (string.IsNullOrEmpty(_SqlConStr) )
_SqlConStr= ConfigurationManager.AppSettings["ConnectionString"];
return _SqlConStr;
}
}
private bool GetCon()
{
//if (SqlCon != null)
// return true;
try
{
SqlCon = new SqlConnection(SqlConStr);
SqlCon.Open();
return true;
}
catch (Exception ex)
{
SqlCon = null;
throw ex;
}
}
[WebMethod]
public DataSet GetData(string Sql, out string ExceptionStr)
{
try
{
ExceptionStr = null;
if (!GetCon())
return null;
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds.Tables.Add(dt);
try
{
SqlCommand Command = new SqlCommand(Sql, SqlCon);
SqlDataAdapter adapter = new SqlDataAdapter(Command);
adapter.Fill(dt);
//SqlCon.Close();
return ds;
}
catch (Exception ex)
{
ExceptionStr = ex.Message;
SqlCon.Close();
return null;
}
}
finally
{
SqlCon.Close();
}
}
[WebMethod]
public string ExecSql(string Sql, out string ExceptionStr)
{
try
{
ExceptionStr = null;
if (!GetCon())
return "连接" + "数据库失败";
try
{
SqlCommand Command = new SqlCommand(Sql, SqlCon);
Command.ExecuteNonQuery();
//SqlCon.Close();
return null;
}
catch (Exception ex)
{
ExceptionStr = ex.Message;
SqlCon.Close();
return "执行Sql语句失败,失败原因:" + ex.Message;
}
}
finally
{
SqlCon.Close();
}
}
}
winform部分代码:
public static DataTable GetData(string Sql)
{
DataTable dt = new DataTable();
string Exceptionstr = "";
var _dblib = dblib;
//跟踪到这一步是SQlL的查询字符串是正确的,但是不能再继续跟踪到服务器了
DataSet ds = _dblib.GetData(Sql, out Exceptionstr);
//但是返回的ds值就不是要查询的结果了,很是无助呀
if (ds != null)
{
return ds.Tables[0];
}
MessageBox.Show(Exceptionstr);
return null;
}
public static string ExecSql(string Sql)
{
string Exceptionstr = "";
string falg = "";
var _dblib = dblib;
falg = _dblib.ExecSql(Sql, out Exceptionstr);
if (falg != null)
{
MessageBox.Show(Exceptionstr);
return Exceptionstr;
}
else
{
return null;
}
}
跪求大侠们指点指点,谢谢
建议日志文件按分钟生成,再有问题发生你就可以看是winform出的问题还是service的问题