在 WCF 服务中托管 FireBirdSql 时出现 AccessViolationException

发布于 2024-11-08 16:31:51 字数 278 浏览 0 评论 0原文

我将 WCF 服务作为托管 Windows 服务托管,当使用者/客户端第二次、第三次或第四次调用其方法时,我不断收到 AccessViolationException。崩溃是完全随机的,因此有时直到多次调用后才会崩溃。

以下是带有语法突出显示的代码,以便于阅读: http://pastebin.com/Z3Z06944

查看私有的注释方法“CheckUser”,因为这就是可能发生异常的地方。

I'm hosting the WCF service as a managed Windows service, and I keep getting an AccessViolationException when the consumer/client invokes its method for a second, third or fourth time. The crashes are completely random, so sometimes it might not crash until several more invocations later.

Here's the code with syntax highlighting for easier reading: http://pastebin.com/Z3Z06944

See the comments around the private method "CheckUser", since that's where the exception might be occurring.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

開玄 2024-11-15 16:31:51

我看了你发布的代码,我不明白这与 WCF 有什么关系。你说注释掉调用FireBirdSql(FbCommand?)的代码和AV就会消失。显然问题出在 FireBirdSql 上。尝试更新到最新版本,或将崩溃报告发送给开发人员。 AV(访问冲突)通常是由于 p/invoke 非托管代码互操作层中的问题而发生的。这听起来像是 WCF 场景中会出现的某种多线程问题。

(更新:编辑 OP 问题标题以包含 FbS​​QL 参考)

I had a look at the code you posted, and I don't see what this has got to do with WCF. You say that commenting out the code for invoking the FireBirdSql (FbCommand?) and the AV goes away. Clearly the problem is with FireBirdSql. Try updating to the latest version, or send the crash report to the developers. An AV (access violation) typically occurs with a problem in the p/invoke unmanaged code interop layer. It sounds like some kind of multithreading problem which would be brought out in a WCF scenario.

(update: edited OP question title to include FbSQL reference)

清引 2024-11-15 16:31:51

在您的代码中,您没有显式关闭连接。

由于您正在使用 using 语句,它将被关闭,但可能会有延迟。

如果存在最大连接数并且请求很快到来,则在达到最大连接数时您可能会收到异常。

这可以解释错误的随机性。

编辑

您的代码容易受到 sql server 注入攻击,您应该修复它。

您的问题可能是锁定错误,您是否有用户和密码的索引,如果没有,您正在执行表扫描,这会锁定表。

In your code you are not explicitly closing the connection.

Since you are using the using statement it will get closed but there may be a delay.

If there is a max number of connections and the requests are coming quickly, you could get an exception if the max number is reached.

This would explain the random nature of the errors.

Edit

Your code is vulnerable to an sql server injection attack, you should fix that.

Your problem could be a locking error, do you have an index on user and password, if not you are doing a table scan, which locks the table.

傾旎 2024-11-15 16:31:51

我认为有更好的角色/成员资格提供程序系统,但根据您的代码,您可以使用 TRY/FINALLY 结构和 using 语句来改进它。

    public Boolean AddUser(string user, string pass)
    {
        using (FbConnection con = new FbConnection(ConfigurationManager.ConnectionStrings["DBi"].ConnectionString.ToString()))
        {
            using (FbCommand fbComm = new FbCommand("INSERT INTO users (name, pass) VALUES ('" + user + "','" + pass + "')", con))
            {
                fbComm.Connection.Open();
                if (CheckUser(user, pass, con) == 0)                        
                {
                    fbComm.ExecuteNonQuery();
                    return true;
                }
                fbComm.Connection.Close();
            }
        }
        return false;
    }

祝你有美好的一天!

I'm thinking that there are better Role / Membership provider systems in place but based on your code, you could improve this with TRY/FINALLY contructs, with the using statement.

    public Boolean AddUser(string user, string pass)
    {
        using (FbConnection con = new FbConnection(ConfigurationManager.ConnectionStrings["DBi"].ConnectionString.ToString()))
        {
            using (FbCommand fbComm = new FbCommand("INSERT INTO users (name, pass) VALUES ('" + user + "','" + pass + "')", con))
            {
                fbComm.Connection.Open();
                if (CheckUser(user, pass, con) == 0)                        
                {
                    fbComm.ExecuteNonQuery();
                    return true;
                }
                fbComm.Connection.Close();
            }
        }
        return false;
    }

Have a great day!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文