如何指定我的应用程序应该使用跟踪标志参数启动SQL Server LocalDb?

时间:2022-09-27 20:48:18

My application uses a LocalDb instance to store it's data. I've noticed a quirk in the way that LocalDb has allocated identifies (explained more here) which I'd like to avoid. The linked answer explains that this can be done by setting an SQL Server trace flag, and explains how to do this for "full fat" SQL Server.

我的应用程序使用LocalDb实例来存储它的数据。我注意到LocalDb分配标识的方式有一个怪癖(这里有更多解释),我想避免。链接的答案解释了这可以通过设置SQL Server跟踪标志来完成,并解释如何为“全脂”SQL Server执行此操作。

Is it possible to set a trace flag on LocalDb? As my application starts it on demand, could this be done through the connection string?

是否可以在LocalDb上设置跟踪标志?当我的应用程序按需启动时,可以通过连接字符串完成吗?

1 个解决方案

#1


4  

I have a similar problem and believe I have a workaround...

我有类似的问题,并相信我有一个解决方法......

Launch Regedit and find your localdb registry key. For me this was

启动Regedit并找到您的localdb注册表项。对我来说这是

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12E.LOCALDB\MSSQLServer\

Within this key create another key named Parameters.

在此键中创建另一个名为Parameters的键。

Within the Parameters key create a string (REG_SZ) named SQLArg0 and set its value to -T272.

在Parameters项中,创建一个名为SQLArg0的字符串(REG_SZ),并将其值设置为-T272。

Stop the LocalDB process by running SQLLOCALDB.EXE in a command prompt, passing in stop as a parameter and the name of the instance. For example:

通过在命令提示符中运行SQLLOCALDB.EXE来停止LocalDB进程,将stop作为参数和实例的名称传递。例如:

C:\> sqllocaldb stop mssqllocaldb

And then cause LocalDB to auto start by connecting to a database on it.

然后通过连接到它上面的数据库使LocalDB自动启动。

Run the query DBCC TRACESTATUS() and you should see that the trace flag 272 is present. For example:

运行查询DBCC TRACESTATUS(),您应该看到跟踪标志272存在。例如:

C:\>sqlcmd -S (LocalDB)\MSSQLLocalDB -Q "DBCC TRACESTATUS();"

To test this I've been using VS2015 server explorer to explore the database. Killing the LocalDB process in Task Manager (sqlservr.exe), connecting to the database in VS2015 and adding a new row manually causes my auto-increment value to jump by 1000. After adding the registry hack described above, manually terminating the LocalDB process doesn't cause the next generated identity value to skip.

为了测试这个,我一直在使用VS2015服务器资源管理器来探索数据库。在任务管理器(sqlservr.exe)中杀死LocalDB进程,连接到VS2015中的数据库并手动添加新行会导致我的自动增量值跳过1000.添加上述注册表hack后,手动终止LocalDB进程不要导致下一个生成的标识值跳过。

HTH

#1


4  

I have a similar problem and believe I have a workaround...

我有类似的问题,并相信我有一个解决方法......

Launch Regedit and find your localdb registry key. For me this was

启动Regedit并找到您的localdb注册表项。对我来说这是

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12E.LOCALDB\MSSQLServer\

Within this key create another key named Parameters.

在此键中创建另一个名为Parameters的键。

Within the Parameters key create a string (REG_SZ) named SQLArg0 and set its value to -T272.

在Parameters项中,创建一个名为SQLArg0的字符串(REG_SZ),并将其值设置为-T272。

Stop the LocalDB process by running SQLLOCALDB.EXE in a command prompt, passing in stop as a parameter and the name of the instance. For example:

通过在命令提示符中运行SQLLOCALDB.EXE来停止LocalDB进程,将stop作为参数和实例的名称传递。例如:

C:\> sqllocaldb stop mssqllocaldb

And then cause LocalDB to auto start by connecting to a database on it.

然后通过连接到它上面的数据库使LocalDB自动启动。

Run the query DBCC TRACESTATUS() and you should see that the trace flag 272 is present. For example:

运行查询DBCC TRACESTATUS(),您应该看到跟踪标志272存在。例如:

C:\>sqlcmd -S (LocalDB)\MSSQLLocalDB -Q "DBCC TRACESTATUS();"

To test this I've been using VS2015 server explorer to explore the database. Killing the LocalDB process in Task Manager (sqlservr.exe), connecting to the database in VS2015 and adding a new row manually causes my auto-increment value to jump by 1000. After adding the registry hack described above, manually terminating the LocalDB process doesn't cause the next generated identity value to skip.

为了测试这个,我一直在使用VS2015服务器资源管理器来探索数据库。在任务管理器(sqlservr.exe)中杀死LocalDB进程,连接到VS2015中的数据库并手动添加新行会导致我的自动增量值跳过1000.添加上述注册表hack后,手动终止LocalDB进程不要导致下一个生成的标识值跳过。

HTH