小编Mik*_*sdf的帖子

SELECT*中有时会丢失计算列

在SQL Azure中,我有一个或多或少像这样设置的表,有两个计算列(IsExpiredIsDeadlineExpired),只是将不可为空的日期时间列与当前时间进行比较:

CREATE TABLE [dbo].[Stuff]
(
   [StuffId] int NOT NULL IDENTITY(1,1),
   [Guid] uniqueidentifier NOT NULL,
   [ExpirationDate] datetime NOT NULL,
   [DeadlineDate] datetime NOT NULL,
   [UserId] int NOT NULL,
   [IsExpired] AS CAST((CASE WHEN [ExpirationDate] < GETUTCDATE() THEN 1 ELSE 0 END) AS bit),
   [IsDeadlineExpired] AS CAST((CASE WHEN [DeadlineDate] < GETUTCDATE() THEN 1 ELSE 0 END) AS bit),
   CONSTRAINT [PK_StuffId] PRIMARY KEY ([StuffId]),
   CONSTRAINT [UNQ_Guid] UNIQUE([Guid]),
)
GO
Run Code Online (Sandbox Code Playgroud)

我有一个包含多个结果集的存储过程,其中一个结果集:

SELECT * FROM [dbo].[Stuff] WHERE [Guid] = @guid
Run Code Online (Sandbox Code Playgroud)

我最近发现表明,有时当结果集读取错误日志SqlDataReader …

sql azure azure-sql-database

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

在Azure角色中使用SmtpClient时,"不支持请求的功能"异常

我在Azure Web或Worker角色中使用SmtpClient时遇到异常.

我创建了一个控制台应用程序,通过RDP在角色VM上手动运行以重现:

using System;
using System.Net;
using System.Net.Mail;
using System.Text;

namespace ConsoleApplication1
{
   class Program
   {
      static void Main()
      {
         var mailClient = new SmtpClient("mail.redacted.com", 587);
         mailClient.EnableSsl = true;
         mailClient.DeliveryFormat = SmtpDeliveryFormat.International;
         mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;

         mailClient.UseDefaultCredentials = false;//SET THIS FIRST OR IT WIPES OUT CREDENTIALS
         NetworkCredential netCreds = new NetworkCredential("mail@redacted.com", "12345 same combination on my luggage");
         mailClient.Credentials = netCreds;

         MailMessage message = new MailMessage();
         message.SubjectEncoding = Encoding.UTF8;
         message.BodyEncoding = Encoding.UTF8;
         message.IsBodyHtml = false;

         message.From = new MailAddress("mike@redacted.com");
         message.To.Add(new MailAddress("mike@redacted.com")); …
Run Code Online (Sandbox Code Playgroud)

.net c# azure smtpclient

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

如何防止 SqlPackage.exe 在部署 dacpac 时删除和重新创建约束?

我有一个 Visual Studio sql 项目,其表定义如下:

CREATE TABLE [dbo].[Hoerses]
(
   [HoersId] INT NOT NULL PRIMARY KEY,
   [DatePurchased] datetime NOT NULL CONSTRAINT [DF_Hoerses_DatePurchased] DEFAULT DATETIMEFROMPARTS(1985,01,01,0,0,0,0)
)
Run Code Online (Sandbox Code Playgroud)

当我使用“脚本”命令定位预先存在的 SQL 数据库时

sqlpackage.exe /Action:Script /SourceFile:DatabaseProject1.dacpac  /Profile:publish.xml /OutputPath:deployscript_test.sql /TargetPassword:redacted
Run Code Online (Sandbox Code Playgroud)

然后,即使约束前后具有相同的名称和定义,我也会得到以下生成的 SQL:

PRINT N'Dropping [dbo].[DF_Hoerses_DatePurchased]...';


GO
ALTER TABLE [dbo].[Hoerses] DROP CONSTRAINT [DF_Hoerses_DatePurchased];


GO
PRINT N'Creating [dbo].[DF_Hoerses_DatePurchased]...';


GO
ALTER TABLE [dbo].[Hoerses]
    ADD CONSTRAINT [DF_Hoerses_DatePurchased] DEFAULT DATETIMEFROMPARTS(1985,01,01,0,0,0,0) FOR [DatePurchased];


GO
PRINT N'Update complete.';


GO
Run Code Online (Sandbox Code Playgroud)

(我对试图阻止这种多余的重新创建的主要担忧是因为当它试图在实际部署/发布期间删除约束时,我偶尔会看到“超出锁定请求超时期限。”错误)

sql sql-server sqlpackage

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

枚举ToString和性能

我正在对一些C#代码进行概要分析,并最终研究了ToString的枚举值的实现。

ToString方法最终调用System.Type.GetEnumName。这是相关的源代码,摘自http://referencesource.microsoft.com/#mscorlib/system/type.cs

public virtual string GetEnumName(object value)
{
    if (value == null)
        throw new ArgumentNullException("value");

    if (!IsEnum)
        throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
    Contract.EndContractBlock();

    Type valueType = value.GetType();

    if (!(valueType.IsEnum || Type.IsIntegerType(valueType)))
        throw new ArgumentException(Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value");

    Array values = GetEnumRawConstantValues();
    int index = BinarySearch(values, value);

    if (index >= 0)
    {
        string[] names = GetEnumNames();
        return names[index];
    }

    return null;
}

// Returns the enum values as an object array.
private Array GetEnumRawConstantValues()
{
    string[] names;
    Array values;
    GetEnumData(out names, out values); …
Run Code Online (Sandbox Code Playgroud)

.net c# enums tostring

5
推荐指数
0
解决办法
1387
查看次数