连接字符串中的AllowUserVariables - SQL Server Express

时间:2016-11-29 21:19:01

标签: c# sql sql-server-express

我试图在我的连接字符串中添加“AllowUserVariables = true”以使用C#访问SQL Server Express。但是抛出了Keyword not supported: 'allowuservariables'.异常。 我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

尝试"允许用户变量= True"

Link

答案 1 :(得分:0)

只有ms sql server才能执行以下命令:

package publicservice

import (
    "time"
    "github.com/hashicorp/consul/api"
    "github.com/hashicorp/consul/testutil"
    "testing"
    "github.com/xtgo/uuid"
)

func TestAcquireLock(t *testing.T) {
    consul := testutil.NewTestServer(t)
    defer consul.Stop()

    firstClient, err := api.NewClient(&api.Config{
        Address: consul.HTTPAddr,
    })

    if err != nil {
        t.Fatalf("failed to create first client with %v", err)
    }

    secondClient, err := api.NewClient(&api.Config{
        Address: consul.HTTPAddr,
    })

    if err != nil {
        t.Fatalf("failed to create second client with %v", err)
    }

    lockKey := "sample-lock-key"

    firstLock, err := firstClient.LockOpts(&api.LockOptions{
        Key: lockKey,
        SessionName: uuid.NewRandom().String(),
    })

    if err != nil {
        t.Fatalf("failed to create first lock %v", err)
    }

    firstResult, err := firstLock.Lock(nil)

    t.Logf("=====> result for first lock is %v", firstResult)

    if err != nil {
        t.Fatalf("failed to acquire first lock %v", err)
    }

    defer firstLock.Unlock()

    secondLock, err := secondClient.LockOpts(&api.LockOptions{
        Key: lockKey,
        LockTryOnce: true,
        LockWaitTime: time.Second,
        SessionName: uuid.NewRandom().String(),
    })

    if err != nil {
        t.Fatalf("failed to create second lock %v", err)
    }

    secondResult, err := secondLock.Lock(nil)

    if secondResult != nil || err != nil {
        t.Fatal("should not have acquired lock here")
    }
}