将直接数据库访问代码移植到WCF [英] Porting direct database access code to WCF

查看:67
本文介绍了将直接数据库访问代码移植到WCF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常大的项目,有超过200个Entity类,我正在通过直接连接进行所有数据库访问。

好​​的是我将数据库访问层分开了项目和该项目将从WCF服务引用。



Hi, I have a really big project with more than 200 Entity classes and I am doing all the database access via direct connection.
Good thing is that I kept my database access layer separate in a project and that project would be referenced from WCF service.

public bool Insert()
       {
           try
           {
               dc = new LinqDataContext1();
               dc.Connection.Open();
               using (dc.Transaction = dc.Connection.BeginTransaction())
               {
                   dc.InsertPayee(1, PayeeID, PayeeName, StreetAddress, City, State.StateID, ZipCode, PhoneNumber, EmailAddress, Notes, (Carrier == null ? null : Carrier.CarrierID), IsActive, GlobalModels.Register.RegisterID);

                   dc.Transaction.Commit();
                   return true;
               }
           }
           catch
           {
               //dc.Transaction.Rollback();
               throw;
           }
           finally
           {
               if (dc.Connection.State == ConnectionState.Open)
               {
                   dc.Connection.Close();
               }
           }
       }

public LinqDataContext1(string p_ConnectionString = "")
        {
            if (string.IsNullOrWhiteSpace(p_ConnectionString) == false)
            {
                connectionString = p_ConnectionString;
            }
            else
            {
                connectionString = GlobalModels.conString;
            }
            Connection = new MySqlConnection(connectionString);
           
        }





目前,每个客户端应用程序都将其数据库连接字符串保存在全局变量中,但是在WCF服务的情况下每次调用Payee.Insert()时,我都必须发送一个新的连接字符串。我的问题是,如果有很多客户端调用相同的服务方法并且执行了多个数据库查询,并且在WCF中工作时我应该注意什么呢?

,这可能导致将来出现任何问题

我尝试过:



我已将现有数据库访问项目的参考添加到WCF服务应用程序。



Currently every client application keeps it's database connection string in global variable but in case of WCF service I would have to send a new connection string every time I call Payee.Insert(). My question is that could it cause any problem in future when there are lots of clients calling same service method and multiple database queries are executed and what are the things I should be careful about when working in WCF?

What I have tried:

I have added reference to existing database access project to WCF service application.

推荐答案

你如何逻辑地将每个数据库分开?是客户名称还是客户编号?你可以通过每个wcf方法调用传递客户名称/ id,然后生成连接字符串,你绝对不应该将连接字符串传递给你的wcf方法。
How do you logically have each database separated? Is it by name as in customer name or customer number? You could pass the customer name/id with each wcf method call and then generate the connection string, you definitely should not pass a connection string to your wcf method.


这篇关于将直接数据库访问代码移植到WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆