我的所有代码都可以正常工作:
using System.Diagnostics;
namespace WebPortalLogging
{
public static class EventLogging
{
public static void LogEvent(string origin, string message, EventLogEntryType eventLogEntryType, int eventId)
{
const string source = "Software";
const string log = "Application";
if (!EventLog.SourceExists(source))
EventLog.CreateEventSource(source, log);
EventLog.WriteEntry(source, message, eventLogEntryType, eventId);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我甚至在另一个项目中使用这个类,它工作正常.当它到达这一行时:
if(!EventLog.SourceExists(source))EventLog.CreateEventSource(source,log);
它击中了这条线并退出.
这是我的输出中的内容:
The thread 'vshost.NotifyLoad' (0x28c) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x470) has exited with code 0 (0x0).
'VmBackup.vshost.exe' (Managed (v4.0.30319)): Loaded 'D:\Google Drive\Code\VMBackup\VMBackup\bin\Debug\VmBackup.exe', Symbols loaded.
'VmBackup.vshost.exe' (Managed (v4.0.30319)): Loaded …Run Code Online (Sandbox Code Playgroud) 我有这行代码:
strKey &= Strings.StrDup(intKeySize - intLength, chrKeyFill)
Run Code Online (Sandbox Code Playgroud)
C#中这段代码的等价物是什么?我似乎找不到它.
我正在使用SqlMembershipProvider与asp.net,它工作正常,直到我尝试使用iframe或帧.
当我没有他们登录时,我没有任何问题,但如果我从我们客户的网站包装我们的网站,并尝试登录,它只是闪烁并返回到原始网站,所有字段都已清除.
我可以在IE 8和9上使用我们的网站轻松复制这个,但我对firefox或chrome没有任何问题.
还有另一种方法可以实现这个目标或绕过它吗?
======编辑======
我们的客户正在从他们的网站上调用我们的"门户网站",并希望将我们的门户网站无缝集成到其中,就好像它是他们网站的一部分一样.
我们认为我们可以通过iframe将我们的门户网站从他们的网站包装来实现这一目标,但我对使用登录工作没有任何好运,从我所看到的是一个跨域cookie问题(?).
希望这有助于澄清一些事情......
我是MsSql的新手,我不确定是否可以这样做,但我想我之前想问一下当前的流程.
我需要创建一个循环遍历数据库中所有表的脚本,并删除其中CorporationId ="xxx"的行.有几个表没有这个列,但在我的~50个表中,只有1个或2个表没有.
我可以单独删除表中的记录:
USE MyDatabase
DECLARE @CorporationId UniqueIdentifier
DECLARE @TokenId UniqueIdentifier
DECLARE @CompanyCode nChar(3)
SET @CorporationId = '52D3AEFE-8EBD-4669-8096-4596FE83BB36'
print 'Starting Web.GasOrder'
DELETE FROM Web.GasOrder
WHERE CorporationId = @CorporationId
print 'Starting Web.GasOrderNumber'
DELETE FROM Web.GasOrderNumber
WHERE CorporationId = @CorporationId
etc..
Run Code Online (Sandbox Code Playgroud)
但是为每张桌子制作一张桌子变得乏味.
当然,有些表与它们有关系.
有没有一种简单的方法可以做到这一点,还是我需要手动为每个表做?
UPDATE
我尝试过的大多数选项遇到了关系问题并给我一个错误.
这是我试图将数据网格绑定到的代码:
var query = (from s in entity.Sources
where s.CorporationId == corporationId
select new SourceItem
{
CorporationId = s.CorporationId,
Description=s.Description,
IsActive = s.IsActive,
Name=s.Name,
SourceId=s.SourceId,
TokenId=s.TokenId
});
var x = new ObservableCollection<Source>(query);
Run Code Online (Sandbox Code Playgroud)
这是我的SourceItetm类:
private void SourceDataGrid_AddingNewItem(object sender, System.Windows.Controls.AddingNewItemEventArgs e)
{
var sources = new Source();
sources.CorporationId = _corporationId;
sources.Description = string.Empty;
sources.IsActive = true;
sources.Name = string.Empty;
sources.SourceId = Guid.NewGuid();
sources.TokenId = Guid.NewGuid();
e.NewItem = sources;
}
public class SourceItem
{
private Guid _corporationId1;
private string _description;
private bool _isActive; …Run Code Online (Sandbox Code Playgroud) 出于某种原因,我遇到了Interfaces的问题.我知道已经发布了100个例子,但显然我不够聪明,无法弄明白......
我有以下界面:
namespace DocStore.Interfaces
{
public interface IResetCategoryControl
{
string CategoryToAdd { set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我想将CategoryToAdd设置为一个值.
这是我想要设置它的课程以及到目前为止我所拥有的课程:
public partial class AddDocumentsDialog : IResetCategoryControl
public string CategoryToAdd
{
set
{
IResetCategoryControl() ireset = new IResetCategoryControl();
ireset.CategoryToAdd = value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在AddDocumentDialog类中做错了什么?我不能让那部分工作.
谢谢!
Eroc
我需要为我的应用程序创建一个单独的线程来记录一些事情,并建议我使用Task.
我似乎没有这个权利,因为我不完全理解任务(我猜).
这是我有的:
public static void LogException(string message, Exception ex)
{
Action action= delegate() { logException(message, ex); };
new Task(action);
}
public static void logException(string message, Exception ex)
{
var stackTrace = new StackTrace();
var origin = stackTrace.GetFrame(1).GetMethod().Name;
var originclass = stackTrace.GetFrame(1).GetMethod().ReflectedType.Name;
var neworigin = string.Format("{0}.{1}", originclass, origin);
message += Environment.NewLine + Environment.NewLine + GetFullExceptionMessage(ex);
if (string.IsNullOrEmpty(message)) message = "No message given";
//var exceptions = GetAllErrMessages(ex);
//message = exceptions.Aggregate(message, (current, exception) => current + Environment.NewLine + exception);
EventLogging.LogEvent(neworigin, message, EventLogEntryType.Error, …Run Code Online (Sandbox Code Playgroud) 我正在尝试更改当前数据库的恢复模型.
这就是我所拥有的:
DECLARE @dbName VARCHAR(50)
SELECT @dbName = DB_NAME()
ALTER DATABASE @dbName SET RECOVERY SIMPLE WITH NO_WAIT
Run Code Online (Sandbox Code Playgroud)
@dbName 给我:
'@dbName'附近的语法不正确.
我试过了:
ALTER DATABASE database_id SET RECOVERY SIMPLE WITH NO_WAIT
Run Code Online (Sandbox Code Playgroud)
database_id 给我:
消息5011,级别14,状态5,行3用户无权更改数据库'database_id',数据库不存在,或者数据库未处于允许访问检查的状态.
我该如何在当前数据库上执行此操作?
我正在尝试将连接字符串保存到配置文件,但密码未提交.
这是我正在使用的代码:
using (var con = new SqlConnection(string.Format("Data Source={0};Initial Catalog={3};User ID={1};Password={2};",
textBox_SqlServer.Text, textBox_Username.Text, textBox_Password.Text, comboBox_DatabaseName.Text)))
{
// test connection before continuing
con.Open();
configs.ApplicationConfiguration.SetConnectionString(con.ConnectionString);
}
Run Code Online (Sandbox Code Playgroud)
一切都很好,直到con.ConnectionString它不包括密码.我需要做什么呢?当然,当我去检索它时,密码就不存在了.
如何设置密码呢?
我看到旧帖子可以删除超过X天的文件,例如这个批处理文件可以删除超过N天的文件.我想为此添加一个额外的过滤器,这样如果我运行的备份没有发生2周,那么它就不会删除我的所有备份.
我知道这个:
forfiles -p "C:\what\ever" -s -m *.* -d <number of days> -c "cmd /c del @path"
Run Code Online (Sandbox Code Playgroud)
您可以删除超过X天但是如何添加上述条件并让它在删除之前留下最少的Z文件?
例:
假设我想删除超过14天的文件,但至少保留5个文件,其中包含以下文件:
Jan 1 - backup1.zip
Jan 2 - backup2.zip
Jan 3 - backup3.zip
Jan 4 - backup4.zip
Jan 5 - backup5.zip
Jan 6 - backup6.zip
Jan 7-20 no backups done
Jan 21st - script runs and removed old files
Run Code Online (Sandbox Code Playgroud)
使用示例代码删除超过14天的所有文件,我的所有备份文件都将被删除,而且我没有备份.我希望脚本看到只剩下6个文件,并保留至少5个文件.
合理?这可能通过Windows批处理文件?
提前致谢!
为了清晰
这是我的批处理文件的一部分:
cd /d %BKUPDIR%
FOR /f "skip=14 delims=" %%A IN ('DIR /a:-d /b /o:-d /t:c %1*.zip …Run Code Online (Sandbox Code Playgroud)