假设我有以下一次性类和示例代码来运行它:
public class DisposableInt : IDisposable
{
private int? _Value;
public int? MyInt
{
get { return _Value; }
set { _Value = value; }
}
public DisposableInt(int InitialValue)
{
_Value = InitialValue;
}
public void Dispose()
{
_Value = null;
}
}
public class TestAnInt
{
private void AddOne(ref DisposableInt IntVal)
{
IntVal.MyInt++;
}
public void TestIt()
{
DisposableInt TheInt;
using (TheInt = new DisposableInt(1))
{
Console.WriteLine(String.Format("Int Value: {0}", TheInt.MyInt));
AddOne(ref TheInt);
Console.WriteLine(String.Format("Int Value + 1: {0}", TheInt.MyInt));
} …Run Code Online (Sandbox Code Playgroud) 每当我通过在profile.ps1脚本中加载管理单元来启动PowerShell时,我都希望能够使用SQL Server PowerShell扩展.我在这里找到了一篇文章,其中有一个脚本示例,说明了如何执行此操作,这在我的32位Windows XP框中运行良好.
不幸的是,在我的64位Windows 7机器上,这种情况爆发了.如果我尝试使用64位PowerShell启动此脚本,我会得到:
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2.
At C:\Users\xxxx\Documents\WindowsPowerShell\profile.ps1:84 char:13
+ Add-PSSnapin <<<< SqlServerCmdletSnapin100
+ CategoryInfo : InvalidArgument: (SqlServerCmdletSnapin100:String
[Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
Run Code Online (Sandbox Code Playgroud)
如果我在32位PowerShell中运行它,我得到:
Get-ItemProperty : Cannot find path 'HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds \Microsoft.SqlServer.Management.PowerShell.sqlps' because it does not exist.
At C:\Users\xxxx\Documents\WindowsPowerShell\profile.ps1:39 char:29
+ $item = Get-ItemProperty <<<< $sqlpsreg
+ CategoryInfo : ObjectNotFound: (HKLM:\SOFTWARE\...owerShell.sqlps:String) [Get-ItemProperty], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我希望能够在64位PowerShell中运行它.为此,我追踪了我认为的Powershell扩展dll,并在64位管理员提升的PowerShell中运行:
cd "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn" …Run Code Online (Sandbox Code Playgroud) 我有一种情况,我需要从一个表中获取"消耗的数量",并将其应用于具有1个或多个"合并批量"数量的行的第二个表.我不确定如何更好地描述它,这是我从表格的角度来看的意思:
Table Pooled_Lots
----------------------------
Id Pool Lot Quantity
1 1 1 5
2 1 2 10
3 1 3 4
4 2 1 7
5 3 1 1
6 3 2 5
Table Pool_Consumption
----------------------------
Id PoolId QuantityConsumed
1 1 17
2 2 8
3 3 10
Run Code Online (Sandbox Code Playgroud)
我需要一个SQL查询的结果行集,如下所示:
Pool Lot Quantity QuantityConsumed RunningQuantity RemainingDemand SurplusOrDeficit
1 1 5 17 0 12 NULL
1 2 10 17 0 2 NULL
1 3 4 17 2 0 2
2 1 7 8 …Run Code Online (Sandbox Code Playgroud) 在编码转换为UTF-8时,我遇到了Windows平台之间的一些奇怪行为.如果我有一个带有"扩展ASCII"字符的字符串,比如商标符号的字符0x99,我可以使用以下代码在Windows 7上转换它:
using System.Text;
...
string DefaultEncodedStr = <<Some string with Extended ASCII chars like 0x99 for TM>>
byte[] DefaultEncodedBytes = Encoding.Default.GetBytes(DefaultEncodedStr);
byte[] UTF8EncodedBytes = Encoding.Convert(Encoding.Default, Encoding.UTF8, DefaultEncodedBytes);
char[] UTF8Chars = new char[Encoding.UTF8.GetCharCount(UTF8EncodedBytes, 0, UTF8EncodedBytes.Length)];
UTF8.GetChars(UTF8EncodedBytes, 0, UTF8EncodedBytes.Length, UTF8Chars, 0);
string UTF8Str = new string(UTF8Chars);
Run Code Online (Sandbox Code Playgroud)
但是,此代码无法转换Windows Server 2008 R2上的初始字符串 - "扩展ASCII"字符仍存在于最终字符串中.
但是,此代码适用于Windows Server 2008 R2:
using System.Text;
...
string DefaultEncodedStr = <<Some string with Extended ASCII chars like 0x99 for TM>>
byte[] DefaultEncodedBytes = Encoding.Default.GetBytes(DefaultEncodedStr)
string UTF8Str = Encoding.UTF8.GetString(DefaultEncodedBytes);
Run Code Online (Sandbox Code Playgroud)
但是,此代码无法转换Windows …