创建自定义SQL Server侦听器以连接到共享的localdb实例吗?

时间:2019-08-01 10:15:59

标签: sql-server localdb sql-server-2017

SQL LocalDB 2017中似乎存在一个巨大的错误,导致从任何版本都无法访问所有共享实例。

static StringBuffer getHTMLFormatted(String textpart, Font font) {

    StringBuffer htmlstring = new StringBuffer();
    ...
    boolean hasColor = false;
    ...
    if(font.toString().contains("<main:color rgb")) { 
              String color = getColor(font);
              htmlstring.append("<font color=#").append(color).append(">") ;
              hasColor = true ;
        }

   }

    htmlstring.append(textpart);
    ...
    if (hasColor) {
        htmlstring.append("</font>");
    }
    return htmlstring;
}

public static String getColor(Font font){
        String colorStr ;
        Pattern pattern = Pattern.compile("<main:color rgb=\"(.*?)\"/>");
        Matcher matcher = pattern.matcher(font.toString());
        if (matcher.find())
        {
            Log.i(TAG , "font color = : " + matcher.group(1));
            colorStr = matcher.group(1);
            colorStr = colorStr.substring(2);
        }else {
            colorStr = "616A6B" ; // my defualt color
        }

        return colorStr;
}

我现在可以使用自定义登录名连接到本地和共享实例。

这时,我仅在命令屏幕保持打开状态时执行SqlLocalDB.msi x64 / 2017。

C:\Windows\system32>sqllocaldb create TestInstance 12.0
LocalDB instance "TestInstance" created with version 12.0.2000.8.

C:\Windows\system32>sqllocaldb share TestInstance SharedInstance
Private LocalDB instance "TestInstance" shared with the shared name: "SharedInstance".

C:\Windows\system32>sqllocaldb start TestInstance
LocalDB instance "TestInstance" started.

C:\Windows\system32>sqllocaldb info TestInstance
Name:               TestInstance
Version:            12.0.2000.8
Shared name:        SharedInstance
Owner:              TSTWCD03\lan
Auto-create:        No
State:              Running
Last start time:    01/08/2019 11:50:18
Instance pipe name: np:\\.\pipe\LOCALDB#SH1FE0E0\tsql\query

C:\Windows\system32>powershell
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Windows\system32> $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
PS C:\Windows\system32>
PS C:\Windows\system32> $SqlConnection.ConnectionString = "Data Source=(localdb)\TestInstance;Integrated Security=true;Connect Timeout=10"
PS C:\Windows\system32> $SqlConnection.Open();
PS C:\Windows\system32>
PS C:\Windows\system32> $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
PS C:\Windows\system32> $SqlCmd.Connection = $SqlConnection
PS C:\Windows\system32>
PS C:\Windows\system32> $SqlCmd.CommandText = "CREATE LOGIN[testlogin] WITH PASSWORD = 'testpass', CHECK_EXPIRATION = OFF, CHECK_POLICY = OFF";
PS C:\Windows\system32> $SqlCmd.ExecuteNonQuery();
-1
PS C:\Windows\system32>
PS C:\Windows\system32> $SqlCmd.CommandText = "ALTER SERVER ROLE[sysadmin] ADD MEMBER[testlogin]";
PS C:\Windows\system32> $SqlCmd.ExecuteNonQuery();
-1
PS C:\Windows\system32> $SqlConnection.Close();
PS C:\Windows\system32> $SqlConnection.ConnectionString = "Data Source=(localdb)\TestInstance;Integrated Security=false;User ID=testlogin;Password=testpass;Connect Timeout=10"
PS C:\Windows\system32> $SqlConnection.Open();
PS C:\Windows\system32> $SqlConnection.State
Open
PS C:\Windows\system32> $SqlConnection.Close();
PS C:\Windows\system32> $SqlConnection.ConnectionString = "Data Source=(localdb)\.\SharedInstance;Integrated Security=false;User ID=testlogin;Password=testpass;Connect Timeout=10"
PS C:\Windows\system32> $SqlConnection.Open();
PS C:\Windows\system32> $SqlConnection.State
Open
PS C:\Windows\system32> $SqlConnection.Close();

因此,当我的2014实例启动(localdb)时,似乎有些更改。\ SharedInstance将不再链接到我的共享实例。

我想知道..有没有办法注册我自己的sql server侦听器?当我可以创建一个额外的侦听器,例如(MyOwnDB)\ MyInstance并将其指向共享实例时。.这不会被2017安装覆盖。

灌输似乎有限。有人可以帮忙吗?

0 个答案:

没有答案