【发布时间】:2010-07-28 16:47:39
【问题描述】:
这可能是一个简单的...
现在我有一个可用的 Web 服务(用 C# 编程),它提供了两个 Web 方法,可以读取或写入数据到 MS SQL 数据库。我想知道的是……当多个用户尝试连接、读取和写入数据库时,我是否需要担心错误?此外,当他们访问数据库时,我是否应该在我的 web 方法中使用线程和锁(现在,我没有使用线程或锁)?
这是我现在运行的一些想法(代码 sn-p):
[WebMethod(Description = "Attempts to post a new score to the scoreboard.")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public TextMessage UpdateScoreboard(string password, string playerName,
int level, int gameBoard, string auth)
{
SqlDataReader myReader = null;
SqlCommand myCommand = null;
SqlConnection myConnection = null;
/*
The method then attempts to connect to the DB,
look for a duplicate playerName, and if there isn't one,
data is entered into the DB ... using the INSERT command.
*/
}
谢谢。
【问题讨论】:
标签: c# .net sql-server web-services