webservice的winform局域网软件在多人同时访问是出现查询sql2000数据表混乱

kzlyan 2012-10-13 11:40:28
为啥只允许我给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;
}
}
跪求大侠们指点指点,谢谢
...全文
200 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
agatone 2012-11-08
  • 打赏
  • 举报
回复
这个问题这么解呀, 我也碰到了这个问题 请高人指点呀
bdmh 2012-10-13
  • 打赏
  • 举报
回复
怎么个不对呢,如果对同一个表,又是插入又是删除,又是查询,那就有可能乱,别人删掉了或修改了某些条件,你再去查,就不对了
Eric_2014SH 2012-10-13
  • 打赏
  • 举报
回复
这问题确实比较怪,你要不在winform端和webservice端都打上日志,记录下执行的sql语句和返回的表名,同时要有执行的时间
建议日志文件按分钟生成,再有问题发生你就可以看是winform出的问题还是service的问题
kzlyan 2012-10-13
  • 打赏
  • 举报
回复
我这出现的问题是查询A表结果给出B表的结果,并不是数据不对而是整个结构都不对

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧