DbaTools Error. How to fix 'Could not load file or assembly 'Microsoft.SqlServer.ConnectionInfo' when running Export-DbaInstance - powershell-4.0

I'm running
Export-DbaInstance -SqlInstance $sourceServerName -Path $absPathToBackupScriptDir
and getting the error 'Could not load file or assembly 'Microsoft.SqlServer.ConnectionInfo'
I tried installing Microsoft Visual C++ Redistributable for Visual Studio 2013 and 2017
I tried adding the DLL in question(which IS contained in the DbaTools module) to the GAC using the CMD below
gacutil.exe /i "C:\Program Files\WindowsPowerShell\Modules\dbatools\bin\smo\Microsoft.SqlServer.ConnectionInfo.dll"
I tried installing the newest version of DbaTools(~0.9.x at time of writing) using the Powershell below
Invoke-Expression (Invoke-WebRequest -UseBasicParsing https://dbatools.io/in)
Inputted command and complete outputted error message are both below
Export-DbaInstance -SqlInstance $sourceServerName -Path $absPathToBackupScriptDir
'Could not load file or assembly 'Microsoft.SqlServer.ConnectionInfo' Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 or one of its dependencies. The system cannot find the file specified.'

If I opt out of exporting replication settings, there is no attempt to load the problematic assembly, and the cmdlet runs as expected.
Export-DbaInstance -SqlInstance $sourceServerName -Path $absPathToBackupScriptDir -Exclude 'ReplicationSettings'

Related

How install Oracle package for Oracle.ManagedDataAccess.dll in VS Code

I'm trying to install the above package in VS Code. For some reason when I put this at the top of my script I get an error message.
using namespace system.collections.generic
Add-Type -AssemblyName System.Data.OracleClient
Add-Type -Path "C:\Users\me\OneDrive - company\Documents\2021\temp endToEnd\oracle.ManagedDataAccess.Core\oracle.manageddataaccess.core.3.21.50\lib\netstandard2.1\Oracle.ManagedDataAccess.dll"
Error:
Add-Type : Missing an argument for parameter 'AssemblyName'. Specify a parameter of type 'System.String[]' and try again.
I also tried Add-type -Path "C:\Users\me\OneDrive - company\Documents\2021\temp endToEnd\oracle.ManagedDataAccess.Core\oracle.manageddataaccess.core.3.21.50\lib\netstandard2.1\Oracle.ManagedDataAccess.dll"
And it had this error:
Add-Type : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
My question is, how do I load this, so I can do the following:
$connectionString = "Data Source=$dataSource;User Id=$username;Password=$password;"
$con = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionString)
I am trying to install this package because I have this error when I try to execute the last code line above:
New-Object : Cannot find type [Oracle.ManagedDataAccess.Client.OracleConnection]: verify that the assembly containing this type is loaded.
I tried doing it through nuget manager as well, with ctrl shift P, nuget manager, but it's not coming up in the list that I can see (odp.net, oracle managed..., etc).
I had download this from the oracle website:
oracle.manageddataaccess.core.3.21.50.nupkg
Then I used 7-zip to unzip it to the location I'm Add-Type from.
I've been looking at these links:
New-object Oracle.ManagedDataAccess.Client.OracleConnection
oracle-developer-tools-vs-code
install nuget package in vs code
I can't seem to get this installed so the command works in the script. Any help would be appreciated.
You're basically treating powershell like a client application, you'll want: the Oracle Data Application Client(ODAC) driver, powershell is a managed memory model so you'll want the managed one, and most likely the 64-bit one unless for some reason you're running 32-bit powershell... Beyond that it'll likely depend on which version works best for your Oracle database.
For example 12cR1:
Download ODP.NET_Managed_ODAC122cR1.zip
extract odp.net\managed\common\Oracle.ManagedDataAccess.dll
PS C:\working> add-type -path (ls .\Oracle.ManagedDataAccess.dll).FullName
PS C:\working> $OraEntry = '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=database.example.com)(Port=1234)))(CONNECT_DATA=(service_name=BigData)))'
PS C:\working> $con = [Oracle.ManagedDataAccess.Client.OracleConnection]::new()
PS C:\working> $con.ConnectionString = "Data Source=$OraEntry;User Id=$username;Password=$password"
PS C:\working> $con.Open()
If you don't know what the OraEntry should be you can likely copy it from your tnsnames.ora and/or check with your database admin
Have a look at How the Runtime Locates Assemblies
Most common .NET assemblies are loaded either from current directory or from Global Assembly Cache (GAC). The GAC takes precedence over locally stored files.
Check files in your downloaded package, there should be the OraProvCfg.exe. Use it for adding the dll into GAC and doing the configuration:
OraProvCfg.exe /action:config /product:odpm /frameworkversion:v4.0.30319 /providerpath:"C:\Users\me\OneDrive - company\Documents\2021\temp endToEnd\oracle.ManagedDataAccess.Core\oracle.manageddataaccess.core.3.21.50\lib\netstandard2.1\Oracle.ManagedDataAccess.dll"

How to overcome "Could not load type 'Microsoft.Cct.Services.Sqm.IWatSqmService'" without updating?

I'm getting the same error message as in this question: Could not load type 'Microsoft.Cct.Services.Sqm.IWatSqmService' Unfortunately, I cannot upgrade to Azure SDK 2.9, as the top answer there suggests.
Specifically, I get this error in a message box whenever I try to package my Azure Cloud Service project:
What's interesting is that I can start the same project in the emulator, which I would assume involves packaging it.
Things I've tried:
Ensuring that I only have version 2.8.2 of the emulator installed (I may have had 2.9 installed initially)
Reinstalling version 2.8.2 of the SDK
Manually copying the Windows Azure Tools from C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0 to the v14.0 equivalent.
Ensuring that C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.8 exists
Reinstalling Visual Studio (so you know I'm desperate!)
And I've no idea what to try next. I can't work out which DLL is supposed to hold the Microsoft.VisualStudio.WindowsAzure.Services assembly, I can't find any references in any config files, and all the Google hits seem to point back to the SO question linked above.
What's going on? And how can I fix it?
In case I'm being an idiot, here's all the Azure-related things I've got installed:
Also (just in case it's relevant) I'm on Windows 7 SP1.
Update 17/01/16
Following some advice from the excellent Rest Azured Slack channel, I've tried using ProcMon and Fusion Log to diagnose this (spoiler: without success)
ProcMon filtered to that assembly returns nothing:
Fusion log (set to log everything) yields lots of entries like this:
* Assembly Binder Log Entry (17/01/2017 # 11:52:02) *
The operation was successful. Bind result: hr = 0x0. The operation
completed successfully.
Assembly manager loaded from:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under
executable C:\Program Files (x86)\Microsoft Visual Studio
14.0\Common7\IDE\devenv.exe
--- A detailed error log follows.
=== Pre-bind state information === LOG: DisplayName = Microsoft.VisualStudio.WindowsAzure.Services, Version=1.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio
14.0/Common7/IDE/ LOG: Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = devenv.exe Calling assembly
: Microsoft.VisualStudio.WindowsAzure, Version=2.9.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
=== WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with
Assembly.Load(). WRN: No matching native image found. LOG: IL assembly
loaded from C:\Program Files (x86)\Microsoft Visual Studio
14.0\Common7\IDE\Extensions\Microsoft\Windows Azure Tools\Microsoft.VisualStudio.WindowsAzure.Services.dll.
When I explore the DLL mentioned, I can find Microsoft.Cct.Services.Sqm, but it doesn't contain a type IWatSqlService:
This feels like it's the crux of the issue, but I've no idea what to do next. Presumably I'd need to replace the DLL with a version that does define IWatSqlService, but I'm not sure where I'd get one. Or, for that matter, why it would even be necessary.
Next stop is probably a full wipe of the machine.
I've had the same problem, and solved it by not using the Web Platform Installer.
Download all parts (Microsoft Azure SDK for .NET - 2.8.2) from the Microsoft site: https://www.microsoft.com/en-us/download/details.aspx?id=50041 and follow the instructions how to install them.
For anyone else with this problem. I ended up resolving this by nuking it from orbit. Fresh install of Windows, reinstall VS and the SDK.
Confusingly, you can also see this error when you add a new
<setting name="TODO" />
element to your *.csdef file but either:
forget to add the corresponding <setting name="TODO" value="TODO" /> element to every *.cscfg file, or
accidentally add a duplicate <setting name="TODO" value="TODO" /> element to any of the *.cscfg files.

Unable to debug .NET Core app

I'm having and issue with Visual Studio and a .NET Core API project. It's been working fine but something must have changed because I'm now getting the following output when trying to debug the project:
The program '[18032] dotnet.exe' has exited with code -2147450749 (0x80008083).
The program '[17688] iisexpress.exe' has exited with code 0 (0x0).
The program '[5500] iexplore.exe' has exited with code -1 (0xffffffff).
The event viewer is showing this error:
Failed to start process with commandline '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\ProjectSystem\VSIISExeLauncher.exe" -debug -p "C:\Program Files (x86)\dotnet\dotnet.exe" -a "C:\Projects\Utilities\API\src\API\bin\Debug\netcoreapp1.0\API.dll" -pidFile "C:\Users\username\AppData\Local\Temp\tmp742C.tmp" -wd "C:\BlueSky\Utilities\API\src\API"', ErrorCode = '0x80004005'.
I'm not sure why this is happening, if anyone has any insight into this it would be appreciated.
Do as fallow:
Close Visual Studio
Delete the project.lock.json file (if exists)
If above step won't help then try to remove .vs folder
Open Visual Studio as Administrator (the file will be restored and you shouldn't have problems anymore)
There is also an option to use Kestrel instead of IIS Express but that's just an workaround.

SSRS does not recognize custom DLL

I'm developing SSRS reports via VS2010 on my local machine.
I need to reference from a certain report to a DLL I wrote, The DLL was built at .net framwork 3.5 and I've placed the dll in the following libraries:
1.C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies.
2.C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer\bin
both on my local machine and the server where SSRS is located.
I've also added rssrvpolicy.config file as following:
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Test"
Description="">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer\bin\Test.dll"
/>
Done all that' I've referenced the DLL through the report properties but yet recieved the following error message while previewing the report:
"An error occured during local report processing, The definition of the report X is invalid.
Error while loading code module "Test ...' Could not load file or assembly 'Test ...' or one of its dependenies. The system cannot find the file specified"
Any ideas?
OK found the problem!
Apperntly installing VS2010 on win7 64 bit create two Microsoft Visual Studio 10.0 folders, one in Program Files where I've located my DLL and one in Program Files (x86) where I should have located it.
Once the DLL was put in the correct folder the report recognized it.
Thanks for your reply

Where is TextTransform.exe Located on Hard drive?

Where is TextTransform.exe located?
I'm trying to implement the solution in this post:
Get Visual Studio to run a T4 Template on every build
However I'm getting an error
"'TextTransform.exe' is not recognized as an internal or external command,
operable program or batch file."
I have been looking through the program files, however not sure where TextTransform.exe is located.
It should be below
\Program Files\Common Files\Microsoft Shared\TextTemplating\
see: http://msdn.microsoft.com/en-us/library/bb126245.aspx
Anyone coming to this question that's using VS 2017 or later should be using vswhere to locate this file. #codingdave's comment is the closest but that still won't work on many computers.
I've added an example to the Microsoft Docs article feedback that shows how to do this with Powershell.
#the path to VSWhere.exe is always in programfiles(x86)
$progFilesx86Path = [System.Environment]::ExpandEnvironmentVariables("%programfiles(x86)%")
$vsWherePath = Join-Path $progFilesx86Path "\Microsoft Visual Studio\Installer\vswhere.exe"
# this tells vswhere to use paths of the latest version of visual studio installed
# to locate this exe anywhere in those paths, and return a single textual
# value (not a json object or xml payload)
$ttExe = & $vsWherePath -latest -find **\TextTransform.exe -format value
if (-Not(Test-Path $ttExe)){
throw "Could not locate TextTransform.exe"
}
#then to invoke a transformation
& "$ttExe" c:\Source\YourTransform.tt
From #codingdave's comment
For VS2017, VS2019 location of TextTransform.exe will be
C:\Program Files (x86)\Microsoft Visual Studio\<<Version>>\<<Edition>>\Common7\IDE
Version -> (2017/2019)
Edition -> (Community/Professional/Enterprise)
And in pre build event we can use macro like
"$(DevEnvDir)\TextTransform.exe" "$(ProjectDir)AssemblyInfo.tt"
I would recommend trying this over that solution: http://www.olegsych.com/2010/04/understanding-t4-msbuild-integration
If you don't have VS 2010, though, I suppose you're stuck doing it the hard way.

Resources