我有一个使用Linq to SQL与数据库进行通信的C#应用程序,一个月前我上一次对其进行测试时工作正常。但是,它现在引发以下异常:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
------ Exception ------
Error: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 0 - The received certificate has expired.)
Run Code Online (Sandbox Code Playgroud)
我正在使用Verisign密钥对代码进行数字签名,但尚未过期。在构建安装程序之前,我不会进行数字签名,并且这是在调试中的开发系统上发生的,因此代码尚未签名。
在签署并安装了该软件的其他系统上也发生了这种情况。这些系统访问与我在dev系统上使用的测试数据库相同的数据库,并且以前可以正常工作。
导致错误的代码行如下:
List<req> results = new List<req>();
using (var db = new MyDbDataContext(connectionString))
{
var query =
from item in db.reqs
where item.senddate == null
select item;
results = query.ToList();
}
Run Code Online (Sandbox Code Playgroud)
我致电时发生错误results = …
我使用Visual Studio 2010在64位系统上开发了一项服务.该服务只是一个访问辅助库中的Start和Stop方法的框架.该库访问64位COM对象,并且必须构建为x64.COM对象是一个单独构建为x64并在64位环境中测试的DLL.我有一个安装程序,用于设置项目并通过自定义操作安装服务.
我使用绕过服务的测试应用程序调试代码,因此我可以确认服务正在访问的库是否正常工作.
我遇到的问题是安装时出现BadImageFormatException.我正在使用目标平台为x64的安装程序.如果我将所有内容构建为x64,我会收到以下消息:
Error 1001. Exception occured while initializing the installation: System.BadImageFormatException. Could not load file or assembly... or one of its dependencies. An attempt was made to load a program with an incorrect format.
Run Code Online (Sandbox Code Playgroud)
如果我将服务设置为构建为任何CPU,则安装正常,并且服务可以访问库,但无法找到COM对象.如果我删除安装该服务的自定义操作,则安装也将起作用.如果我然后尝试使用installutil手动安装服务,我会收到与上面相同的错误消息.
下面是我在服务中使用的库的列表.
using System;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using MAPIMail;
using MAPIMail.Logging;
Run Code Online (Sandbox Code Playgroud)
请注意,MAPIMail项目正在构建为x64.
有没有人知道为什么我不能专门安装x64作为x64系统上的任何CPU安装服务.我感谢任何和所有的建议.
我正在使用NetworkStream来保持可以发送消息的开放TCP/IP连接.我收到一条消息,处理它,然后返回一个ACK.我正在使用一个偶尔收到消息的站点,但是当我发送ACK时,我得到一个IOException.有时这只持续一两条消息(我可以接收下一条消息),有时它会一直持续到服务停止并重新启动.
下面是我的NetworkStream的代码,没有任何处理:
using (NetworkStream stream = client.GetStream())
{
stream.ReadTimeout = ReadTimeout;
...
if (stream.CanRead && stream.DataAvailable)
bytesRead = stream.Read(receivedBytes, 0, BufferSize);
...
stream.Write(ack, 0, ack.Length);
}
Run Code Online (Sandbox Code Playgroud)
请注意,代码在读取新消息和发送ACK之间循环.
当我打电话时stream.Write,我有时会得到以下异常:
System.IO.IOException: Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace --- …Run Code Online (Sandbox Code Playgroud) 我们公司刚刚更名,我正在重新命名一些软件的品牌。我遇到的一个问题是我们将事件日志写入为Company Name.ProductName. 有没有一种方法可以更改源的日志,而无需删除并重新创建源。
我已经能够确定与源相关的日志,但不确定如何更改日志而不删除除更改产品名称之外的现有数据,而我不想这样做。
if (!System.Diagnostics.EventLog.SourceExists("ProductName"))
{
System.Diagnostics.EventLog.CreateEventSource(
"ProductName", "Company Name");
}
else if (!EventLog.LogNameFromSourceName("ProductName", ".").Equals("Company Name"))
{
// ??? Not sure what to do here ???
}
eventLog.Source = "ProductName";
eventLog.Log = "Company Name";
eventLog.WriteEntry("The Service has been created.");
Run Code Online (Sandbox Code Playgroud) 我正在重构代码,该代码使用Thread.Sleep越来越长的时间限制来在出现错误时重试 SQL 查询。阻塞的常见替代Thread.Sleep似乎是await Task.Delay,这需要将方法更改为async. 该方法现在如下所示(为简洁起见,删除了额外的错误检查):
private static async Task<int> PrepareForRetry( int retryCount, SqlCommand command, int timeout )
{
++retryCount;
if (retryCount < ConnectionRetryCount)
{
int SleepTime = _connectionRetryBackoffTimes[retryCount - 1] + (_connectionRetryRandomBackoff.Next() % 500);
//Thread.Sleep(SleepTime);
await Task.Delay(SleepTime);
}
return retryCount;
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是async要求调用方法为async,等等。虽然最终重构为完全异步,但这远远超出了当前的重构范围。
我遇到的问题是如何从同步代码调用该方法并获取结果。使用
retryCount = PrepareForRetry(retryCount, command, timeout).Result;
Run Code Online (Sandbox Code Playgroud)
由于 UI 线程正在调用该方法,因此会造成死锁。我发现我可以通过将我的更改Task.Delay为
await Task.Delay(SleepTime).ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)
但我不完全明白这是做什么的。我也尝试过使用调用该方法
retryCount = Task.Run(async () => { await PrepareForRetry(retryCount, command, timeout).Result; });
Run Code Online (Sandbox Code Playgroud)
但这有错误“'int'不包含'GetAwaiter'的定义”,并且我无法找出如何继续获得结果。使用 …
我有一个 SQL 命令,我试图将其转换为 LINQ to SQL 命令,但遇到了困难。
我的 SQL 命令如下:
SELECT purchs.iclientid, ifeatureid, AddnlOptionList FROM purchs
WHERE AddnlOptionList <> ''
GROUP BY purchs.iclientid, ifeatureid, AddnlOptionList
HAVING (SUM(noptions) > 0)
Run Code Online (Sandbox Code Playgroud)
我已经成功地做到了以下示例:
var q =
from purchs in db.Purchases
group q by purchs.noptions into g
where purchs.AddnlOptionList != ""
&& g.Sum(x => x.noptions) > 0
select q;
Run Code Online (Sandbox Code Playgroud)
但是,我似乎被困在 q 组中,出现以下两个错误:
Cannot use local variable 'q' before it is declared
Cannot convert lambda expression to type 'System.Collections.Generic.IEqualityComparer<decimal?> because it is not a delegate …Run Code Online (Sandbox Code Playgroud) c# ×6
linq-to-sql ×2
async-await ×1
asynchronous ×1
event-log ×1
exception ×1
ioexception ×1
sql-server ×1
sqlexception ×1
task ×1
tcp ×1