小编sjo*_*urg的帖子

如何清除connectiontrings的configurationmanager缓存

我试图在运行时更改位于Servicehost的App.Config中的connectionstring中的数据库名称,然后在连接到另一个数据库后重新启动它.这样可以正常工作,但前提是应用程序关闭多秒钟.关闭应用程序几秒钟似乎清除了ConfigurationManager.Connectionstrings的缓存.问题是由于这个需要的关机时间,我不能在我的应用程序中使用Application.Restart().

这种缓存行为的奇怪之处在于,即使在内存中更新了值(在第二次请求时的示例中),也会正确显示更新后的值.但是当应用程序重新启动时,旧值似乎重新出现.

要验证行为,请创建新的控制台应用程序.

添加App.Config文件

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="DomainDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=InitialDBName;Integrated Security=SSPI;" />
  </connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

然后将以下代码添加到Main方法

        ConfigurationManager.RefreshSection("connectionStrings");
        DbConnectionStringBuilder builder = new DbConnectionStringBuilder();
        Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        builder.ConnectionString = appConfig.ConnectionStrings.ConnectionStrings["DomainDBConnectionString"].ConnectionString;

        //print initial value
        Console.WriteLine("initial " + (string)builder["Initial Catalog"]);

        //change value
        builder["Initial Catalog"] = "ChangedDatabaseName";
        appConfig.ConnectionStrings.ConnectionStrings.Remove("DomainDBConnectionString");
        appConfig.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("DomainDBConnectionString", builder.ConnectionString));
        appConfig.ConnectionStrings.SectionInformation.ForceSave = true;
        appConfig.Save(ConfigurationSaveMode.Full);
        ConfigurationManager.RefreshSection("connectionStrings");

        Console.ReadLine();

        DbConnectionStringBuilder builder2 = new DbConnectionStringBuilder();
        Configuration appConfig2 = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        builder2.ConnectionString = appConfig.ConnectionStrings.ConnectionStrings["DomainDBConnectionString"].ConnectionString;
        Console.WriteLine("changed " + (string)builder2["Initial Catalog"]);

        Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

要重现此行为,您需要运行应用程序(通过按F5)并关闭它.之后,solutionname.exe.config文件将显示修改后的值.如果您再次运行该应用程序(这次双击solvename.exe),如果您在终止应用程序后立即执行此操作,或者等待几秒钟后,您会发现行为上的差异.

在我看来,由于ConfigurationManager.RefreshSection("connectionStrings"),应该重新读取configsection; 但似乎这不像宣传的那样有效.

.net configurationmanager connection-string runtime

5
推荐指数
2
解决办法
6033
查看次数

Microsoft Sync Framework与Nhibernate TooManyRowsAffectedexception冲突

我们正在尝试将Microsoft Sync Framework实现到我们的应用程序中,该应用程序使用NHibernate持久化它的域.

我们遇到的一个问题是,在Sync Framework更改了您的初始数据库结构(添加影子表和触发器)之后,当您尝试将对象插入数据库时​​,NHibernate似乎会因为抛出toomanyrowsaffectedexception而感到不安.

我发现这篇文章的解决方案是在每个更新语句周围添加SET NOCOUNT ON和OFF,但由于表结构由nhibernate自动生成,同步触发器由Sync Framework自动生成,因此手动调整所有触发器实际上不是一个选项.

http://www.codewrecks.com/blog/index.php/2009/03/25/nhibernate-and-toomanyrowsaffectedexception/

我尝试按照此问题中的描述设置sql server 2008属性NOCOUNT:哪里是设置NOCOUNT的最佳位置? 但是这导致了StaleStateException(受影响的行数为-1,预期为1).

您是否知道是否有办法配置同步框架以在其触发器中自动设置这些NOCOUNT语句?或者有没有办法告诉NHibernate期望更多/更少的行被更改?或者也许你们中的任何人都有一个自动脚本来将这些NOCOUNT语句添加到同步框架的触发器中.

Thx提前!

.net c# nhibernate nocount microsoft-sync-framework

5
推荐指数
1
解决办法
1806
查看次数

我可以在没有 Visual Studio 的情况下将报表部署到报表服务器 (SSRS) 吗?

我在我的电脑上本地创建了一个报告,现在我想将其推送到客户的生产环境。

我是否需要要求客户安装 Visual Studio 才能部署报告?

还有什么其他方法可以将报告发送到这台我无法从本地计算机连接到的生产计算机?

publish visual-studio-2010 reporting-services ssrs-2012

5
推荐指数
1
解决办法
4657
查看次数

(Caliburn Micro)将ActionMessage方法名映射到ViewModel的子对象

我想将caliburn.micro actionmessage的methodname propererty绑定到ViewModel的子对象上的方法.

我怎么想象它应该工作:

<i:Interaction.Triggers>
  <i:EventTrigger EventName="Click">
    <cal:ActionMessage MethodName="MenuItemX.Clicked" />
  </i:EventTrigger>
</i:Interaction.Triggers>
Run Code Online (Sandbox Code Playgroud)

这里的问题是methodname不直接存在于viewmodel上,而是存在于viewmodel的子对象上.

所以在这种情况下我想绑定到:ViewModel.MenuItemX.Clicked()

目前的解决方法是在我的viewmodel上使用pass-through方法.

silverlight caliburn.micro

4
推荐指数
1
解决办法
1431
查看次数

如何以编程方式编辑虚拟模式下datagridview的单元格值?

我在虚拟模式下有一个DataGridView.我只实现了如http://msdn.microsoft.com/en-us/library/15a31akc.aspx中所述的CellValueNeeded事件处理程序.

当您希望能够手动编辑单元格时,似乎只需要实现其余事件.

我想以编程方式编辑DataGridView单元格值.

我使用以下代码尝试了这个:

DataGridView1.EditMode = DataGridViewEditMode.EditProgrammatically;
DataGridView1.BeginEdit(false);
DataGridView1.Rows[0].Cells[0].Value = "testing new value";
//just using a random parameter here, not sure it is needed when editing programmatically
DataGridView1.CommitEdit(DataGridViewDataErrorContexts.LeaveControl);
DataGridView1.Refresh();
Run Code Online (Sandbox Code Playgroud)

但没有成功:(

任何帮助,将不胜感激

c# virtual datagridview editing winforms

3
推荐指数
1
解决办法
9799
查看次数

c#casting to type from typename as string

我想解决我的WCF服务层无法处理这样的泛型方法的事实:

public void SaveOrUpdateDomainObject<T>(T domainObject)
{           
    domainRoot.SaveDomainObject<T>(domainObject);
}
Run Code Online (Sandbox Code Playgroud)

所以我建立了这个变通方法

public void SaveOrUpdateDomainObject(object domainObject, string typeName)
{           
    Type T = Type.GetType(typeName);
    var o = (typeof(T))domainObject;
    domainRoot.SaveDomainObject<typeof(T)>(o);
}
Run Code Online (Sandbox Code Playgroud)

问题是这不会以某种方式编译.

我认为这是我没有完全理解两者之间差异的结果

  • 类型TI认为这是"类型"类型的对象

  • typeof(T)的结果我相信这会导致T类型的非对象类型版本(我不知道怎么说这个)

c# types casting typeof gettype

2
推荐指数
1
解决办法
6520
查看次数

为什么不列出<T> .GetHashCode和ObservableCollection <T> .GetHashCode评估他们的项目?

我认为这些集合的GetHashCode函数不会将其哈希码基于其列表中的项目,这很奇怪.

我需要这个才能提供脏检查(你有未保存的数据).我编写了一个覆盖GetHashCode方法的包装类,但我发现这不是默认实现,这很奇怪.

我想这是性能优化?

class Program
{
    static void Main(string[] args)
    {
        var x = new ObservableCollection<test>();
        int hash = x.GetHashCode();
        x.Add(new test("name"));
        int hash2 = x.GetHashCode();

        var z = new List<test>();
        int hash3 = z.GetHashCode();
        z.Add(new test("tets"));
        int hash4 = z.GetHashCode();

        var my = new CustomObservableCollection<test>();
        int hash5 = my.GetHashCode();
        var test = new test("name");
        my.Add(test);
        int hash6 = my.GetHashCode();
        test.Name = "name2";
        int hash7 = my.GetHashCode();
    }
}

public class test
{
    public test(string name)
    {
        Name = name; …
Run Code Online (Sandbox Code Playgroud)

c# hashcode

1
推荐指数
1
解决办法
460
查看次数