Connecting to SQL 2014 via PowerShell - sql

This has me stumped.
.NET version 4.7
Powershell 5.1
I am trying to use the : new-object System.Data.SqlClient.SqlConnection statement
to connect to a MS-SQL server.
The code connects when run as Administrator but fails when run as another user that is a member of Local Administrators group.
The user has (I think) all required SQL permissions and no SQL hardening has been done. It is sysadmin on the server both with a Windows account and a SQL account.
Using
try { new-object System.Data.SqlClient.SqlConnection }
catch { write-host $_.Exception.ToString() }
to simply catch the exception.
It returns Requested registry access is not allowed
Using ProcMon there is absolutely no difference in the registry calls what so ever between the two users except that under administrator 3 threads exit and under the user only 1.
I am not convinced it is an actual registry permission as I gave the account explicit permissions on both HKLM and HKCU in the lab.
If anyone has seen this and/or can recommend a fix please hit me up.
(The script has to run as the user account because it is called from within SQL and therefore invoked under the service account context of the SQL Server Agent)
Here is the exception:
try { new-object System.Data.SqlClient.SqlConnection }
catch { write-host $_.Exception.ToString() }
System.Management.Automation.MethodInvocationException: Exception calling ".ctor" with "0" argument(s): "The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception." ---> System
.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClien
t.SqlConnectionFactory' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SqlPerformanceCounters' threw an exception. ---> System.Security.Se
curityException: **Requested registry access is not allowed.**
at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.PerformanceCounterLib.FindCustomCategory(String category, PerformanceCounterCategoryType& categoryType)
at System.Diagnostics.PerformanceCounterLib.IsCustomCategory(String machine, String category)
at System.Diagnostics.PerformanceCounter.InitializeImpl()
at System.Diagnostics.PerformanceCounter.set_RawValue(Int64 value)
at System.Data.ProviderBase.DbConnectionPoolCounters.Counter..ctor(String categoryName, String instanceName, String counterName, PerformanceCounterType counterType)
at System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp)
at System.Data.SqlClient.SqlPerformanceCounters..ctor()
at System.Data.SqlClient.SqlPerformanceCounters..cctor()
--- End of inner exception stack trace ---
at System.Data.SqlClient.SqlConnectionFactory..cctor()
--- End of inner exception stack trace ---
at System.Data.SqlClient.SqlConnection..cctor()
--- End of inner exception stack trace ---
at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Management.Automation.DotNetAdapter.AuxiliaryConstructorInvoke(MethodInformation methodInformation, Object[] arguments, Object[] originalArguments)
--- End of inner exception stack trace ---
at System.Management.Automation.DotNetAdapter.AuxiliaryConstructorInvoke(MethodInformation methodInformation, Object[] arguments, Object[] originalArguments)
at System.Management.Automation.DotNetAdapter.ConstructorInvokeDotNet(Type type, ConstructorInfo[] constructors, Object[] arguments)
at Microsoft.PowerShell.Commands.NewObjectCommand.CallConstructor(Type type, ConstructorInfo[] constructors, Object[] args)
PS SQLSERVER:>

Related

How do I Provision a Transport Handler for IoTHub?

I am trying to connect to IoTHub to provision my device.
I am in a Blazor WASM app.
I have created the Security Provider Symmetric Key via:
SecurityProvider symmetricKeyProvider = new SecurityProviderSymmetricKey(parameters.DeviceId, parameters.DeviceSymmetricKey, null);
However my next line I call:
ProvisioningTransportHandler mqttTransportHandler = new ProvisioningTransportHandlerMqtt(TransportFallbackType.TcpOnly);
I have tried it with both the TcpOnly fallback along with not passing in any fallback and both give me the same error. The exception is:
Error provisioning device: The type initializer for 'Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt' threw an exception.
System.TypeInitializationException: The type initializer for 'Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt' threw an exception.
---> System.InvalidOperationException: failed to create a child event loop.
---> System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Threading.Thread.Start()
at DotNetty.Common.Concurrency.SingleThreadEventExecutor..ctor(IEventExecutorGroup parent, String threadName, TimeSpan breakoutInterval, IQueue`1 taskQueue)
at DotNetty.Common.Concurrency.SingleThreadEventExecutor..ctor(IEventExecutorGroup parent, String threadName, TimeSpan breakoutInterval)
at DotNetty.Transport.Channels.SingleThreadEventLoop..ctor(IEventLoopGroup parent, String threadName, TimeSpan breakoutInterval)
at DotNetty.Transport.Channels.SingleThreadEventLoop..ctor(IEventLoopGroup parent)
at DotNetty.Transport.Channels.MultithreadEventLoopGroup.<>c.<.cctor>b__24_0(IEventLoopGroup group)
at DotNetty.Transport.Channels.MultithreadEventLoopGroup..ctor(Func`2 eventLoopFactory, Int32 eventLoopCount)
--- End of inner exception stack trace ---
at DotNetty.Transport.Channels.MultithreadEventLoopGroup..ctor(Func`2 eventLoopFactory, Int32 eventLoopCount)
at DotNetty.Transport.Channels.MultithreadEventLoopGroup..ctor()
at Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt..cctor()

How to make Akka.NET's ClusterClient work?

I'm trying out ClusterClient as per the docs.
However my client test app keeps getting the following error:
Error while creating actor instance of type Akka.Cluster.Tools.Client.ClusterClient with 1 args: (Akka.Cluster.Tools.Client.ClusterClientSettings)
Cause: [akka://TestSystem/user/$a#705838478]: Akka.Actor.ActorInitializationException: Exception during creation ---> System.TypeLoadException: Error while creating actor instance of type Akka.Cluster.Tools.Client.ClusterClient with 1 args: (Akka.Cluster.Tools.Client.ClusterClientSettings) ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: failure-detector.heartbeat-interval must be > 0s
at Akka.Remote.DeadlineFailureDetector..ctor(TimeSpan acceptableHeartbeatPause, TimeSpan heartbeatInterval, Clock clock)
at Akka.Remote.DeadlineFailureDetector..ctor(TimeSpan acceptableHeartbeatPause, Clock clock)
at Akka.Cluster.Tools.Client.ClusterClient..ctor(ClusterClientSettings settings)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, Object[] args)
at Akka.Actor.Props.ActivatorProducer.Produce()
at Akka.Actor.Props.NewActor()
--- End of inner exception stack trace ---
at Akka.Actor.Props.NewActor()
at Akka.Actor.ActorCell.CreateNewActorInstance()
at Akka.Actor.ActorCell.<>c__DisplayClass118_0.<NewActor>b__0()
at Akka.Actor.ActorCell.UseThreadContext(Action action)
at Akka.Actor.ActorCell.NewActor()
at Akka.Actor.ActorCell.Create(Exception failure)
--- End of inner exception stack trace ---
at Akka.Actor.ActorCell.Create(Exception failure)
at Akka.Actor.ActorCell.SysMsgInvokeAll(EarliestFirstSystemMessageList messages, Int32 currentState)
The minimal code I'm using to get this error:
using (var system = ActorSystem.Create("TestSystem")) {
system.Settings.InjectTopLevelFallback(ClusterClientReceptionist.DefaultConfig());
var settings = ClusterClientSettings.Create(system);
var client = system.ActorOf(ClusterClient.Props(settings));
Console.Write("Press any key to exit...");
Console.ReadKey();
}
The HOCON config for the client contains:
akka {
actor {
provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
}
remote {
helios.tcp {
port = 0
hostname = localhost
}
}
cluster {
client {
initial-contacts: ["akka.tcp://TestSystem#localhost:8082/user/receptionist"]
}
}
}
Also checked the settings variable, seemed to be populated and looks ok to me:
Tried several random stuff to actually fulfill the error message:
failure-detector.heartbeat-interval must be > 0s
including various permutation of HOCON entries, but to no avail.
Anything else I missed out?
Update #1
Modified HOCON to initialize Akka.Remote.
Still received what looks like the same error message.
But now it is stating:
failure-detector.heartbeat-interval must be > 0s
Previously it was stating:
failure-detector.acceptable-heartbeat-pause must be >= 0s
Managed to make it working now.
The cause of the issue: I was using Akka.Cluster.Tools latest release version 1.0.6
The fix: Upgraded to the latest beta version 1.1.2.30-beta
p/s: I wished the docs could have specified the minimum NuGet version required to make it work.

Sitecore 8.1 : sitecore_fxm_web_index - Root item could not be found

We are using Sitecore 8.1 powered by Lucene index and xDB disabled.
We noticed that the CMS CA is quiet slow. While looking at logs noticed a number of error logged below:
ManagedPoolThread #4 2015:12:18 10:17:05 ERROR [Index=sitecore_fxm_web_index, Crawler=SitecoreItemCrawler, Database=web] Root item could not be found: /sitecore/system/Marketing Control Panel/fxm/.
ManagedPoolThread #15 2015:12:18 10:17:08 ERROR Exception
Exception: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
Source: mscorlib
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj)
at Sitecore.Reflection.MethodInstance.Invoke()
at Sitecore.Jobs.JobRunner.RunMethod(JobArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.PipelineMethod.Invoke(Object[] parameters)
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Pipelines.CorePipeline.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)
at Sitecore.Jobs.Job.ThreadEntry(Object state)
Nested Exception
Exception: System.InvalidOperationException
Message: [Index=sitecore_fxm_web_index, Crawler=SitecoreItemCrawler, Database=web] Root item could not be found: /sitecore/system/Marketing Control Panel/fxm/.
Source: Sitecore.ContentSearch
at Sitecore.ContentSearch.SitecoreItemCrawler.get_RootItem()
at Sitecore.ContentSearch.SitecoreItemCrawler.IsAncestorOf(Item item)
at Sitecore.ContentSearch.SitecoreItemCrawler.IsExcludedFromIndex(IIndexableUniqueId indexableUniqueId, Boolean checkLocation)
at Sitecore.ContentSearch.SitecoreItemCrawler.Update(IProviderUpdateContext context, IIndexableUniqueId indexableUniqueId, IndexEntryOperationContext operationContext, IndexingOptions indexingOptions)
at Sitecore.ContentSearch.AbstractSearchIndex.PerformUpdate(IEnumerable`1 indexableInfo, IndexingOptions indexingOptions)
at Sitecore.ContentSearch.AbstractSearchIndex.Update(IEnumerable`1 indexableInfo)
Could someone please suggest why sitecore is looking for Web forms for marketing index which we don't need it?
Thanks
Sitecore looks for sitecore_fxm_web_index index. It's not a WFFM index - it's Federated Experience Manager Index. This is an integral part of Sitecore 8.1.
Here you can read more about Federated Experience Manager.
Looks like you're missing root item of this index, which is /sitecore/system/Marketing Control Panel/fxm/. I guess you're migration process from Sitecore 7 (which you mentioned in other question) to Sitecore 8.1 was not 100% successful.

Setup fails because of custom action invocation

This is the situation:
When I compile in Debug mode (VS2013), in temporary folder I see LOG file that created with following error:
FXCA: Extracting custom action to temporary directory: C:\Windows\Installer\MSIF661.tmp-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action GlobalCustomActions!GlobalCustomActions.CustomActions.CheckInputParameters
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'GlobalCustomActions.CustomActions' threw an exception. ---> System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at GlobalCustomActions.CustomActions..cctor()
--- End of inner exception stack trace ---
at GlobalCustomActions.CustomActions.CheckInputParameters(Session session)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32 sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)
CustomAction caCheckInputParameters returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 15:56:17: caCheckInputParameters. Return value 3.
Action ended 15:56:17: INSTALL. Return value 3.
Action ended 15:56:17: ExecuteAction. Return value 3.
Action ended 15:56:17: INSTALL. Return value 3.
If I compile in Release, the same code runs good and custom action executes just fine.
And another input: this code was compiled before in Debug mode and worked fine.
I ensured that useLegacyV2RuntimeActivationPolicy set to true and both frameworks are supported.

Program Does Not Run On Win XP But Will Run On Win7

So I designed a program using Visual Studio 2010 on a Win7 box. For the sake of this the program is called Test.exe
When another user, using Win XP tries to open this program, it pops up a Just In Time Debugger window and never runs. I can open the program on my Win7 box and additional Win7 boxes and each time the program opens.
I'm not exactly sure where to begin to figure out why Win XP machines fail to run this program.
Any suggestions?
EDIT
Here is the exception error we got but running the debugger on the XP machine.
System.InvalidOperationException was unhandled
Message=An error occurred creating the form. See Exception.InnerException for details. The error is: Exception has been thrown by the target of an invocation.
Source=WinApp
StackTrace:
at WinApp.My.MyProject.MyForms.Create_Instance_[T](T Instance)
at WinApp.My.MyProject.MyForms.get_Form1()
at WinApp.My.MyApplication.OnCreateMainForm()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WinApp.My.MyApplication.Main(String[] Args)
InnerException: System.Reflection.TargetInvocationException
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeMethodHandle._SerializationInvoke(IRuntimeMethodInfo method, Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)
at System.Runtime.Serialization.ObjectManager.DoFixups()
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
at System.Resources.ResourceReader.DeserializeObject(Int32 typeIndex)
at System.Resources.ResourceReader._LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)
at System.Resources.ResourceReader.LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)
at System.Resources.ResourceReader.LoadObject(Int32 pos, ResourceTypeCode& typeCode)
at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString)
at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase)
at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
at System.Resources.ResourceManager.GetObject(String name)
at WinApp.Form1.InitializeComponent()
at WinApp.Form1..ctor()
InnerException: System.ComponentModel.Win32Exception
Message=The parameter is incorrect
Source=System.Drawing
ErrorCode=-2147467259
NativeErrorCode=87
StackTrace:
at System.Drawing.Icon.Initialize(Int32 width, Int32 height)
at System.Drawing.Icon..ctor(SerializationInfo info, StreamingContext context)
InnerException:
You'll need to make sure that the Windows XP system has the appropriate version of the .NET Framework installed.
Also, there are many types that will not work on XP within .NET framework 4. For example, if you use the MD5Cng class, you'll see (in the "Platforms" section of the docs) that it's only supported on Vista+, not on XP. Using this class in a program will cause an exception if it's run on XP.
Edit:
From your stack trace, it looks like your Form (WinApp.Form1) is using an Icon (.ico) which is a format that is unsupported by Windows XP. For example, if you use a full color icon, this can raise an exception on XP. Make sure it's a 256 color icon file to work properly on XP.