zoukankan      html  css  js  c++  java
  • LinqToEntitiesDomainService Dynamic Binding DataBase ,Silverlight RIA 动态绑定数据库

    手上有个搜索引擎的项目,每个行业都有一个独立的数据库,这些数据库schemas都是一样。这样RIA就需要根据客户选择的不同行业连接到不同的数据库。解决办法参看 链接

    这个方法不是最理想的,大致代码如下

    在silverlight端

    private void SetCookie(string cookieName, string cookieValue)
    {
     
    DateTime expireDate = DateTime.Now + TimeSpan.FromDays(1);
     
    string newCookie = cookieName + "=" + cookieValue + ";expires=" + expireDate.ToString("R");
     
    HtmlPage.Document.SetProperty("cookie", newCookie);
    }

    在RIA端override
    protected override ProjectEntities CreateObjectContext()
    {
     
    long projectId = -1;
     
    StringBuilder connection;
     
    if (System.Web.HttpContext.Current.Request.Cookies["SelectedProjectId"] != null)
     
    {
        projectId
    = Convert.ToInt64(System.Web.HttpContext.Current.Request.Cookies["SelectedProjectId"].Value);
     
    }
     
    else throw new Exception("Selected Project ID Exception");  // temporary

     
    // Verify this user has access to the DB just in case it's spoofed

     
    // Lookup project ID in my database to get the database name and server name

     
    // Load template connection string found in web.config
     
    // Replace the template holders for SERVER_NAME and DATABASE_NAME with above lookup values

     
    return new ProjectEntities(MyDynamicConnectionString);      
    }

  • 相关阅读:
    CentOS7.0 内核(3.10.0-123.el7.x86_64)bug导致KVM物理机重启
    Jenkins控制台输出乱码
    MySQL 主从失败报错:Last_SQL_Errno: 1594
    PHP7添加opcache.so模块
    python 网络爬虫requests模块
    Python 运算符
    tmux使用笔记
    linux使脚本在后台运行
    git 使用钩子直接推送到工作目录
    Git使用笔记
  • 原文地址:https://www.cnblogs.com/mjgb/p/1956978.html
Copyright © 2011-2022 走看看