我从一个exe内部运行一个WCF服务(用于调试,它将在部署时移动到Windows服务)我有一个服务在其中运行良好但是当我运行第二个服务时我得到异常
System.InvalidOperationException was unhandled
Message=The ChannelDispatcher at 'http://backupsvr:8082/' with contract(s) '"IHttpGetHelpPageAndMetadataContract"' is unable to open its IChannelListener.
Source=System.ServiceModel
StackTrace:
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open()
at Service.Program.Main() in E:\Visual Studio 2010\Projects\Contract Flow Suite\Service\Program.cs:line 30
InnerException: System.InvalidOperationException
Message=A registration already exists for URI 'http://backupsvr:8082/'.
Source=System.ServiceModel
StackTrace:
at System.ServiceModel.Channels.UriPrefixTable`1.RegisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, TItem item)
at System.ServiceModel.Channels.HttpTransportManager.Register(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.HttpChannelListener.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan …Run Code Online (Sandbox Code Playgroud) 我有一个绑定到DataTable的DataGridView,它有一个double的列,值必须介于0和1之间.这是我的代码
private void dgvImpRDP_InfinityRDPLogin_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (e.ColumnIndex == dtxtPercentageOfUsersAllowed.Index)
{
double percentage;
if(dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value.GetType() == typeof(double))
percentage = (double)dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value;
else if (!double.TryParse(dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value.ToString(), out percentage))
{
e.Cancel = true;
dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].ErrorText = "The value must be between 0 and 1";
return;
}
if (percentage < 0 || percentage > 1)
{
e.Cancel = true;
dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].ErrorText = "The value must be between 0 and 1";
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我在dgvImpRDP_InfinityRDPLogin_CellValidating火灾时的问题dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, e.RowIndex].Value将包含编辑前的旧值,而不是新值.
例如可以说旧值是1.1和我进入3,上面的代码,当你退出电池,并运行dgvImpRDP_InfinityRDPLogin[e.ColumnIndex, …
这是我想要做的简化版本
static void Main(string[] args)
{
int test = 0;
int test2 = 0;
Test A = new Test(ref test);
Test B = new Test(ref test);
Test C = new Test(ref test2);
A.write(); //Writes 1 should write 1
B.write(); //Writes 1 should write 2
C.write(); //Writes 1 should write 1
Console.ReadLine();
}
class Test
{
int _a;
public Test(ref int a)
{
_a = a; //I loose the reference here
}
public void write()
{
var b = System.Threading.Interlocked.Increment(ref _a); …Run Code Online (Sandbox Code Playgroud) 当我使用一个SqlCommandBuilder推更新/插入/删除服务器,我需要打电话.GetUpdateCommand(),.GetInsertCommand()和.GetDeleteCommand()?
using (var adapter = new SqlDataAdapter("select * from MyTable", _connection))
using (var builder = new SqlCommandBuilder(adapter))
{
adapter.Fill(dt);
//Magic happens
builder.GetUpdateCommand(); //is this line necessary
builder.GetInsertCommand(); //is this line necessary
adapter.Update(dt);
}
Run Code Online (Sandbox Code Playgroud)
我看到有关正确程序的相互矛盾的 例子.我知道没有它可行,但我不知道它是否在幕后做了一些特别的事情.这是必要的还是货物编程?
我有一个应用程序用于管理我们软件演示的数据库,它所做的一件事是从中央服务器获取数据库的副本并将其还原到本地SQL实例.一切都在备份部分正常工作,但在恢复时,有些人报告说他们在恢复过程中遇到以下异常.
Microsoft.SqlServer.Management.Smo.FailedOperationException: Restore failed for Server 'Computername'.
---> Microsoft.SqlServer.Management.Common.ExecutionFailureException:
An exception occurred while executing a Transact-SQL statement or batch.
---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
(snip)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
--- End of inner exception stack trace ---
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
(snip)
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
--- End of inner exception stack trace ---
at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
at ContractFlowTool.WebInfinity2.AttachDatabase.RestoreLocal(AttachDatabaseArgs …Run Code Online (Sandbox Code Playgroud) 我想用一个DateTime属性填充一个viewmodel,还有一个类别列表.
视图模型:
public class TourCategoryVM
{
public DateTime Date { get; set; }
public List<TourCategoryList> TourCategoryList { get; set; }
}
public class TourCategoryList
{
public int TourCategoryId { get; set; }
public string TourType { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
领域模型:
public class TourCategory
{
public int TourCategoryId { get; set; }
public string TourType { get; set; }
public virtual ICollection<Tour> Tour { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想我可以用这段代码轻松填充它:
var viewModel = new TourCategoryVM();
viewModel.TourCategoryList = db.TourCategories();
Run Code Online (Sandbox Code Playgroud)
但是,我收到错误:
错误1无法将类型隐式转换
System.Data.Entity.DbSet<tb.Models.TourCategory> …
背景:
如果我有以下程序
public class Program
{
public static void Main()
{
using(var connection = new SqlConnection("Server=(local);Database=Testing;Trusted_Connection=True"))
using (var command = connection.CreateCommand())
{
connection.Open();
command.CommandText = "UPDATE Foo set Bar = @Text";
command.Parameters.Add("@Text", SqlDbType.VarChar, 50).Value = "Hello World!";
command.ExecuteNonQuery();
}
}
}
Run Code Online (Sandbox Code Playgroud)
执行时,运行以下查询(根据SQL Server Profiler)
exec sp_executesql N'UPDATE Foo set Bar = @Text',N'@Text varchar(50)',@Text='Hello World!'
Run Code Online (Sandbox Code Playgroud)
我的问题:
我想要做的是,如果我有以下
command.CommandText = "UPDATE Foo set Bar = @Text";
command.Parameters.Add("@Text", SqlDbType.VarChar, 50).Value = "Hello World!";
string query = GenerateQuery(command);
Run Code Online (Sandbox Code Playgroud)
GenerateQuery 会返回字符串
"exec sp_executesql N'UPDATE Foo …Run Code Online (Sandbox Code Playgroud) 手动管理数据库连接时,始终打开和关闭它.有时您需要在执行某些操作之前检查连接是否具有某种状态.经典情况是在关闭连接之前检查未关闭状态.就像是
if (connection.State != ConnectionState.Closed)
connnection.Close();
Run Code Online (Sandbox Code Playgroud)
由于MSDN声明ConnectionState是枚举WITH FLAGS.这意味着连接状态可以同时具有不同的状态.可能会被打破+关闭或其他...
如果您反编译System.Data.ConnectionState枚举,您将看到
[Flags]
public enum ConnectionState
{
Closed = 0,
Open = 1,
Connecting = 2,
Executing = 4,
Fetching = 8,
Broken = 16,
}
Run Code Online (Sandbox Code Playgroud)
Closed项的值为ZERO.这意味着以下总是如此:
connection.State.HasFlag(ConnectionState.Closed)
Run Code Online (Sandbox Code Playgroud)
所以.有什么建议为什么这个枚举有Flags属性?或者(如果此枚举必须是Flags)为什么Closed项具有0值?
我维护一个库,我们的大型组织将其用于其ant配置文件。我正在尝试从junit 4后端更新到junit 5后端,同时对最终用户的干扰最小。
我遇到的主要问题是输出格式化程序。我们有一个macrodef,它接受<element name="test-formatter"/>像
<runmultipletest foo=...>
<test-formatter>
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
</test-formatter>
<runmultipletest-fileset>
<fileset refid="${junit.integration.fileset}"/>
</runmultipletest-fileset>
</runmultipletest>
Run Code Online (Sandbox Code Playgroud)
在宏定义内部
<batchtest todir="@{test.todir}" skipNonTests="@{skipNonTests}">
<test-formatter/>
<runmultipletest-fileset/>
</batchtest>
Run Code Online (Sandbox Code Playgroud)
现在我要升级到junit5。在不破坏与最终用户用于转换现有格式的现有格式的向后兼容性的情况下
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
Run Code Online (Sandbox Code Playgroud)
进入
<listener type="legacy-plain" sendSysOut="true" sendSysErr="true"/>
<listener type="legacy-xml" sendSysErr="true" sendSysOut="true" outputDir="@{test.todir}"/>
Run Code Online (Sandbox Code Playgroud)
从我的macrodef内部?我可以弄清楚XSLT可以将xml转换成我想要的格式,但是我对Ant的了解还不够,无法知道是否可以转换传入的元素然后再junitlauncher使用它。
c# ×9
.net ×2
.net-4.5 ×1
ado.net ×1
ant ×1
app-config ×1
asp.net-mvc ×1
datagridview ×1
exception ×1
java ×1
junit ×1
junit4 ×1
junit5 ×1
smo ×1
sql ×1
sql-server ×1
validation ×1
wcf ×1
wcf-binding ×1
windows-8.1 ×1