有没有办法CommandText在.NET中以编程方式替换paramater值?
假设我们有一个命令:
let cmd = conn.CreateCommand()
cmd.CommandText <- "select * from smsqueue where smsqueueid=:pid"
cmd.CommandType <- CommandType.Text
cmd.Parameters.Add("pid", 0)
Run Code Online (Sandbox Code Playgroud)
我想得到准备好的命令文本; 这将是这样的:
select * from smsqueue where smsqueueid=0
Run Code Online (Sandbox Code Playgroud)
有分析器可以获取此信息,但我想在代码中明确地执行此操作(例如,F#或C#).
如何在Windows上构建Go 1文档?它在我的机器上的D:\ go\doc下,所有链接和路径都被破坏了.
我将大量数据插入RavenDB数据库; 大约2 500000条记录.这需要在尽可能短的时间内完成.
我使用一个列表来保存SaveChangesAsync返回的Task对象:
session.Store(loc);
splitter++;
if (splitter % 2048 == 0)
{
var t = session.SaveChangesAsync();
tasks.Add(t);
if (tasks.Count == 2)
{
Task.WaitAll(tasks.ToArray());
tasks.Clear();
}
}
Run Code Online (Sandbox Code Playgroud)
此代码在具有i7(8核)和12 GB RAM的机器上运行.如果我持有的Task对象的数量是2(如您在代码中看到的那样),但是如果我将此数字增加到8(核心数),则会收到System.IndexOutOfRangeException(有时会出现System.AggregateException: Raven.Abstractions.Exceptions.ConcurrencyException:PUT尝试使用非当前的etag文档'X/I'.
这里有什么问题?
谢谢
我想从一个文本文件(每行是一个类似csv的条目)导入1亿个条目到RavenDB数据库.最快的方法是什么?
补充说明:
我还没有任何索引(我会在插入数据后创建它们).RavenDB在本地计算机上以服务模式运行,没有任何安全性增强(但是因为我还在测试RavenDB).该测试将在2台不同的机器上运行,1)2芯4GB内存2)8芯12 GB内存.
我已经完成了将一部分数据(200万个条目)插入到RavenDB中,但它没有我想要的那么快.通过使用OpenAsyncSession并为每1024条记录调用SaveChangesAsync并再次通过调用OpenAsyncSession创建一个新会话,而不是在500'000条目之后等待返回任务(由SaveChangesAsync返回),我得到一个"索引超出范围"异常我无法根除.但是,如果我等待任务结束(通过创建与核心数相同的任务),过程将成功,但速度不够快.
此代码成功运行:
using (var reader = new StreamReader(@"D:\*\DATA.TXT", Encoding.UTF8))
{
string line = null;
IAsyncDocumentSession session = null;
var tasks = new List<Task>();
var locCount = 0;
while ((line = reader.ReadLine()) != null)
{
if (string.IsNullOrWhiteSpace(line)) continue;
var loc = Parse(line);
if (session == null) session = documentStore.OpenAsyncSession();
session.Store(loc);
locCount++;
if (locCount % 1024 == 0 && session != null)
{
try
{
var t = session.SaveChangesAsync();
tasks.Add(t);
session = null;
}
catch (Exception x)
{ …Run Code Online (Sandbox Code Playgroud) 尝试Unmarshal一个hcl配置文件的结构,使用viper,返回此错误:1 error(s) decoding:\n\n* 'NATS' expected a map, got 'slice'。有什么不见了?
编码:
func lab() {
var c conf
// config file
viper.SetConfigName("draft")
viper.AddConfigPath(".")
viper.SetConfigType("hcl")
if err := viper.ReadInConfig(); err != nil {
log.Error(err)
return
}
log.Info(viper.Get("NATS")) // gives [map[port:10041 username:cl1 password:__Psw__4433__ http_port:10044]]
if err := viper.Unmarshal(&c); err != nil {
log.Error(err)
return
}
log.Infow("got conf", "conf", c)
}
type conf struct {
NATS struct {
HTTPPort int
Port int
Username string
Password string
} …Run Code Online (Sandbox Code Playgroud) 如果这是一个太小的问题,请提前道歉.
一位朋友得到了Beginning Rails 3,我们开始使用Ruby(作为.net开发人员!).我在VMWare Player上安装了Ubuntu 10.10 - 显然已经有了Ruby 1.9.2.根据书中的说明(对于整个linux nubs的一些怪癖),我们设法安装了Ruby 1.9.1(ruby --version - > ruby 1.9.1p376(2009-12-07 revision 26041)[i686-linux]).
但Rails(最新版本 - 我认为3.0.2)坚持认为Ruby 1.9.2对我们的健康更有益!
那么:如何在Ubuntu 10.10上更新Ruby?我想要一个红宝石就在那里.
我使用以下方法创建了一个事件日志源:
if (!EventLog.SourceExists(EventLogSource)) EventLog.CreateEventSource(EventLogSource);
Run Code Online (Sandbox Code Playgroud)
因此,使用EventLogSource的每个日志条目都会进入"应用程序".然后我希望所有使用EventLogSource的条目进入另一个自定义日志; 所以我删除了它们然后使用新的自定义日志创建了源:
try { EventLog.DeleteEventSource(EventLogSource); }
catch { }
try { EventLog.Delete(EventLogName); }
catch { }
...
if (!EventLog.SourceExists(EventLogSource)) EventLog.CreateEventSource(EventLogSource, EventLogName);
while (!EventLog.SourceExists(EventLogSource)) { }
Run Code Online (Sandbox Code Playgroud)
但是当我使用EventLogSource进行日志记录时,条目仍然会进入"Application"而不是EventLogName.
注意:
我在评论中写了这篇文章,我认为这有助于更好地描述我的问题:在Windows事件查看器中,您会看到"Windows日志"和"应用程序".树中有另一个名为"Applications and Services Logs"的节点,我想在其下创建一个自定义日志.我能成功地做到这一点.问题是以前注册到"Application"的事件源不能从"Application"取消注册并在我自己的"MyCustomLog"中重新注册.
我有一个具有x和y值的A类列表:
class A
{
public int X { get; set; }
public int Y { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的列表:
List<A> MyList = GetListOfA();
Run Code Online (Sandbox Code Playgroud)
我想通过计算A属性的值来对列表进行排序.例如今天美元汇率乘以X.如果我将使用OrderBy表达式,该方法将计算x*log(x)次.
我找到了一些方法来创建内部类,包括值和变量,匿名类型列表,将包括变量和计算值的列表,通过计算值的键将其添加到排序字典等.
使用简洁明了的语法来实现它的最佳方法是什么?
我想((IStringer)object).ToString()在Erlang中写一些(在C#中).经过一番研究后,我了解到Elixir有一种称为Protocols的东西,它几乎与C#相同(以内向外的方式).然后我在Erlang中提出了这个想法/代码 - 这对我来说非常好:
?stringer(my_val):to_string().
Run Code Online (Sandbox Code Playgroud)
它要么返回预期值,要么返回not_implemented原子!
但有2个问题:
1 - 为什么没有人在Erlang中使用这个或基于有状态模块来推广事物?(OTP除了和一些Erlangers谈话,他们不知道实际上OTP是围绕着这个建立的!所以真的需要改变Erlang的教学和推广方式.我可能会感到困惑.)
2 - 为什么我收到这个警告?那个电话实际上永远不会失败.
警告:
stringer.erl:18: Warning: invalid module and/or function name; this call will always fail
stringer.erl:19: Warning: invalid module and/or function name; this call will always fail
stringer.erl:20: Warning: invalid module and/or function name; this call will always fail
Run Code Online (Sandbox Code Playgroud)
代码:
-module(stringer).
-export([to_string/1,sample/0]).
-define(stringer(V), {stringer, V}).
to_string({stringer, V}) when is_list(V) ->
to_string(V, nop);
to_string({stringer, V}) when is_atom(V) ->
to_string(V, nop);
to_string({stringer, _V}) ->
not_implemented.
to_string(V, _Nop) -> …Run Code Online (Sandbox Code Playgroud)