Error when importing snapshot to SQL Server 2019 - sql-server

There is an Error when I want to import data from a snapshot(bacpac) file into SQL Server 2019.
It has occur twice on my two different PC.
Please help me if there is any solution about that.
Thank you very much!
Error :
Error Details :
Here are the error details:
===================================
Object reference not set to an instance of an object. (Microsoft.Data.Tools.Schema.Sql)
Program Location:
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentPlanGenerator.DeploymentScriptDomGenerator.GenerateFragment(Int32 operation, IModelElement element)
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentPlanGenerator.DeploymentScriptDomGenerator.GenerateSteps(Int32 operation, IModelElement element)
at Microsoft.Data.Tools.Schema.Sql.Deployment.OrderedStepGenerator.Add(DeploymentScriptDomGenerator scriptDom, IModelElement element, Int32 operation)
at Microsoft.Data.Tools.Schema.Sql.Deployment.Analyzers.PlanMediator.BuildDependencyOrderedSteps(Int32 operation, List1 classOrder, List1 operationOrder, Dictionary2 changes, Boolean preserveGraphs, Dictionary2& relating, Dictionary2& related)
at Microsoft.Data.Tools.Schema.Sql.Deployment.Analyzers.PlanMediator.BuildOperations()
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentPlanGenerator.OnGeneratePlan()
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentPlanGenerator.GeneratePlan(List1 drops)
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.BuildPlan()
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.Controller.CreatePlan()
at Microsoft.SqlServer.Dac.DeployOperation.<>c__DisplayClass3.<>c__DisplayClass5.b__1()
at Microsoft.Data.Tools.Schema.Sql.Dac.OperationLogger.Capture(Action action)
at Microsoft.SqlServer.Dac.DeployOperation.<>c__DisplayClass3.b__0(Object operation, CancellationToken token)
at Microsoft.SqlServer.Dac.Operation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
at Microsoft.SqlServer.Dac.ReportMessageOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
at Microsoft.SqlServer.Dac.OperationExtension.CompositeOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
at Microsoft.SqlServer.Dac.OperationExtension.CompositeOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
at Microsoft.SqlServer.Dac.DeployOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
at Microsoft.SqlServer.Dac.OperationExtension.Execute(IOperation operation, DacLoggingContext loggingContext, CancellationToken cancellationToken)
at Microsoft.SqlServer.Dac.DacServices.InternalDeploy(IPackageSource packageSource, Boolean isDacpac, String targetDatabaseName, DacDeployOptions options, CancellationToken cancellationToken, DacLoggingContext loggingContext, Action3 reportPlanOperation, Boolean executePlan)
at Microsoft.SqlServer.Dac.DacServices.ImportBacpac(BacPackage package, String targetDatabaseName, DacImportOptions importOptions, Nullable1 cancellationToken)
at Microsoft.SqlServer.Dac.DacServices.ImportBacpac(BacPackage package, String targetDatabaseName, DacAzureDatabaseSpecification creationDefaults, Nullable`1 cancellationToken)
at Microsoft.SqlServer.Management.Dac.DacWizard.ImportDatabase.DoWork()
at Microsoft.SqlServer.Management.TaskForms.SimpleWorkItem.Run()

I had the same issue and was able to resolve this with previous version of SSMS (SQL Server Management Studio) - not the SQL Server version. Previous SSMS versions can be downloaded here:
https://learn.microsoft.com/en-us/sql/ssms/release-notes-ssms?view=sql-server-ver15#1791
ATTOW, the current version is 18.5. It works for me at version 17.9.1 and 18.4.
This works for me on both SQL Server 2017 and 2019, it was the issue with SSMS, not the SQL Server version.
I also tried Azure Data Studio with SQL Dacpac extension (https://github.com/microsoft/azuredatastudio/tree/master/extensions/dacpac) and it failed with same error as latest SSMS version. There's an issue open for this: https://github.com/microsoft/azuredatastudio/issues/9522
Alternatively, instead of installing SSMS, install sqlpackage from https://learn.microsoft.com/en-us/sql/tools/release-notes-sqlpackage?view=sql-server-ver15#184-sqlpackage (version 18.4) and run the command manually. Something like:
sqlpackage.exe /a:Import /df:"import.log" /sf:"mybacpac-2020-04-26.bacpac" /tcs:"Server=.;Database=mybacpac;Integrated Security=true"

I ran into the exact same error message while attempting to import a BACPAC to my local SQL Server 2019. Exact same error on SQL Server 2017 through my testing. The import failed with the latest versions of SSMS and Azure Data Studio.
In my case the error was thrown due to the existence of an external contained user account in the database, principle type E. Type E is External user from Azure Active Directory.
You can check here for reference:
https://learn.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-database-principals-transact-sql?view=sql-server-ver15
After removing the user account from the database, I was able to import the database successfully.

Same error as well. I updated it to v18.9.2, instead of downgrading it and it resolved the issue

Related

SQL Server Express 2016 user works in SSMS but not from application via internal IP

I am using Google Compute instances with a SQL Server Express 2016 database on one instance and an application on another instance. The database is set up to work with either SQL Server or Windows authentication.
The application connects to the database using the internal IP address. All is well as long as the SQL Server user is sa, but when I change it to another user I set up, it won't connect and gives this error:
An error occurred while executing the command definition. See the inner exception for details.
I looked at the application log which gives a longer error but not helpful (at least to me). But as soon as I change the connection string back to sa, everything is fine.
I am able to access the database via SSMS with the new login, so I know it's legitimate, at least locally. I've restarted the database server several times. Obviously there's something I'm missing; just don't know what it is.
Point taken: Here is the log:
ERROR [2020-06-29 22:39:35,828] [XXXXXXXXXXXX.Controllers.UserController.Authenticate] Unable to Login with Message- An error occurred while executing the command definition. See the inner exception for details.
Stack Trace: at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.b__5()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation) at System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable.GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator1.MoveNext() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source)
at XXXXXXXXXXXX.Controllers.UserController.AuthenticateUser(String userName, String password)
at XXXXXXXXXXXX.Controllers.UserController.Authenticate(String userName, String password, String returnUrl)
XXXXXXXXXXXX.Controllers.UserController.Authenticate(System.String userName, System.String password, System.String returnUrl)
You are correct, it is a permissions issue. If I change the user and give it sysadmin permissions, it works great; however I was hoping to dial down the permissions for this SQL login. Is that not possible/advisable?
Thanks,
Sally

Error while connecting to Database Server from SQL Server Management Studio

Recently, while trying to connect to any SQL Server Database from SQL Server Management Studio, I am getting an error - Service 'Microsoft.SqlServer.Management.IRegistrationService' not found (Microsoft.SqlServer.Management.SDK.SqlStudio)
I tried updating to the latest version of SQL Server Management Studio but there is no change.
The full error stack is as below:
===================================
Service 'Microsoft.SqlServer.Management.IRegistrationService' not found (Microsoft.SqlServer.Management.SDK.SqlStudio)
------------------------------
Program Location:
at Microsoft.SqlServer.Management.ServiceProvider.GetService[T](IServiceProvider serviceProvider, Boolean throwIfNotFound)
at Microsoft.SqlServer.Management.SqlStudio.Explorer.NavigationService.Initialize()
at Microsoft.SqlServer.Management.SqlStudio.Explorer.NavigationService.GetView(String urnPath)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.<GetColumnsFromNavigationService>d__11.MoveNext()
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.AddFields(List`1 list, IEnumerable`1 fields, IDictionary`2 allValidFields, AddFieldsFlags flags)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.GetParentFields(INodeInformation source, Dictionary`2& allValidColumns)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.BuildDynamicItemWithQuery(IList`1 nodes, INodeInformation source, INavigableItem sourceItem, String urnQuery, Boolean registerBuilder, Boolean registerBuiltItems)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.BuildDynamicItem(IList`1 nodes, INodeInformation source, INavigableItem sourceItem, IFilterProvider filter)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItemBuilder.Build(IList`1 nodes, INodeInformation source, INavigableItem sourceItem, IFilterProvider filter)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.NavigableItem.RequestChildren(IGetChildrenRequest request)
at Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ExplorerHierarchyNode.BuildChildren(WaitHandle quitEvent)
Any idea why this error is happening?
What helped in my case... (version 17.9.1)
I have checked file:
C:\Users\<user>\AppData\Roaming\Microsoft\AppEnv\14.0\ActivityLog.xml
In there I have found the information that the directory:
C:\Users\<user>\Documents\SQL Server Management Studio
has not been found.
I have created it manually and... SSMS started working.
Yeah I know... It sounds crazy.
#Marek Malczewski is right, thank you sir!
I too looked at the log files and fixed it the same way, here is a screenshot for your confirmation.
Install .NET 4.8.
I've had exactly the same issue and it worked for me.
Go to C:\Users\ <\users>\Documents
and create a new folder with name SQL Server Management Studio then Restart MSQL server as well.
Hopefully your issue resolved.

How can I see SQL query received by SQL Server

Is there any way for me to see every SQL query string that is received by SQL Server?
My problem is: I deployed IIS server. I got errors like below when browse job by ID. I think the quick way is view the SQL strings sent to SQL Server.
But I didn't know how. Also I didn't see anything in Windows event viewer's app log.
Stack Trace:
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass7.b__5()
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation)
at System.Data.Entity.Core.Objects.ObjectQuery1.GetResults(Nullable1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery1..GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator1.MoveNext()
at System.Linq.Enumerable.Single[TSource](IEnumerable1 source)
at Unity.DataAccessLayer.GetUnityJobRaw(Int32 id) in C:\myrepo\HASH\myhash\hash\Unity\DataAccessLayer.cs:line 588
at Unity.DataAccessLayer.GetUnityJob(Int32 id) in C:\myrepo\HASH\myhash\hash\Unity\DataAccessLayer.cs:line 296
at Hash.Controllers.UnityJobController.d__6.MoveNext() in C:\myrepo\Controllers\UnityJobController.cs:line 128
You can trace every query or stored procedure with SQL Server Profiler
There is profiler in SQL Server 2008 also.
Please refer below link for that.
http://blog.sqlauthority.com/2009/08/03/sql-server-introduction-sql-server-2008-profiler-complete/

SSIS package with status running is not running

I have deployed my SSIS solution to SQL Server 2014. The package is run manually from Management Studio. Randomly, the package shows status running in execution report, but when I connect to to Integration Service using Management Studio it doesn't show any package running. The package just hangs without any error, nor any step is started or completed.
How can I troubleshoot this? What could be causing this error?
Just for the records, I found that the problem rely in a database timeout caused by having too much logs in SSISDB tables.
The SSIS Execution Process could not write to the IS catalog: MAMSQLT02:SSISDB Error details: Unable to add new messages to the table of operation messages.:Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.; at Microsoft.SqlServer.IntegrationServices.Server.ISServerExec.ISServerHelper.AppendEventMessage(SqlCommand cmd, Int64 operationId, Int32 message_type, DateTimeOffset message_time, Int16 message_source, String message_text, Nullable1 extendedInfoId, String packageName, String packageLocationType, String packagePathFull, String eventName, String messageSource, String messageSrcId, String subComponentName, String packagePath, String executionPath, UInt32 threadId, Nullable1 messageCode, Int64& eventMessageId) at Microsoft.SqlServer.IntegrationServices.Server.ISServerExec.BasicEventInfo.WriteInternal(SqlCommand sqlCommand) at Microsoft.SqlServer.IntegrationServices.Server.ISServerExec.Loggable.Microsoft.SqlServer.IntegrationServices.Server.ISServerExec.ILoggable.Write(SqlConnection conn)
Truncating the tables using SP [internal].[cleanup_server_retention_window_truncateall] solved the problem

Issue with OleDbConnection.Open when Running as a Service

We have an Nant build script that we are running through SSH (Cygwin & Open SSH) to remotely upgrade our databases. When the Nant script is launched through an SSH session, the following error is thrown when it attempts to make a database connection. However, if I log in to the server directly (using the same account as the service) and run the Nant scripts by hand, the script executes successfully.
Error Message:
System.InvalidOperationException: The
.Net Framework Data Providers require
Microsoft Data Access
Components(MDAC). Please install
Microsoft Data Access Components(MDAC)
version 2.6 or later.
---> System.IO.FileNotFoundException: Retrieving the COM class factory for
component with CLSID
{2206CDB2-19C1-11D1-89E0-00C04FD7A829}
failed due to the following error:
8007007e.
Stack Trace:
System.InvalidOperationException: The .Net Framework Data Providers require Microsoft Data Access Components(MDAC). Please install Microsoft Data Access Components(MDAC) version 2.6 or later.
---> System.IO.FileNotFoundException: Retrieving the COM class factory for component with CLSID {2206CDB2-19C1-11D1-89E0-00C04FD7A829} failed due to the following error: 8007007e.
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Data.OleDb.OleDbConnectionInternal.CreateInstanceDataLinks()
at System.Data.OleDb.OleDbConnectionInternal.GetObjectPool()
--- End of inner exception stack trace ---
at System.Data.OleDb.OleDbConnectionInternal.GetObjectPool()
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at UpgradeDatabases.UpgradeDatabase.Execute()
After spending lots of time trying to track down the cause, I am stuck. Here are some observations I have made:
The script runs perfectly when I run it manually on the same machine (without SSH). I can even run the script manually, with the same user that the SSH service is running under.
Since the Nant script is running under the context of a service, the issue seems to be related to the User Profile.
The script is executing on a Windows 2008 Server with .NET 3.5 installed. I wouldn't assume that MDAC would be a problem here as the exception indicates
One site states that it might be related to UPHClean (which is a part of the User Profile Service in Windows Server 2008). I haven't been able to confirm that this is actually the problem. I looked in the Event Viewer for Event ID 1530 and there are a few occurrences, but they don't correlate with each execution of the build script.
I installed the native OleDb providers for SQL Server 2008 and the same error occurs.
Does anyone have any advice on how I can track down the root cause of this issue? It really seems to be related to the fact that the code is running under the context of a service. I've used Procmon to try to trace through the execution, but I haven't had any luck finding the culprit. Thanks in advance!
I also had the "The .Net Framework Data Providers require Microsoft Data Access Components(MDAC). Please install Microsoft Data Access Components(MDAC) version 2.6 or later." error when trying to invoke my Windows program over ssh, but not when running the same program directly in a cygwin terminal on the server (Windows Server 2008 R2 Enterprise). I felt sure this could be made to work using openssh in cygwin. Eventually I found that it could be made to work if you sent the following environment variable in the ssh call:
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
So if you logged in like so:
$ ssh myuser#myserver -o SendEnv='CommonProgramFiles(x86)'
Then you should be able to run your program successfully. Note this assumes you have already configured sshd on the server to accept the environment variable. You can do that by adding the following line to /etc/sshd_config and then restarting sshd (net stop sshd followed by net start sshd):
AcceptEnv CommonProgramFiles(x86)
When AccessDatabaseEngine.exe (Microsoft Office Access database engine 2007) is installed (download it from http://www.microsoft.com/en-us/download/confirmation.aspx?id=23734) it puts some files under C:\Program Files (x86)\Common Files.
The problem was definitely related to Cygwin + OpenSSH. I ended up installing WinSSHD and my issue was resolved. So for future reference, be wary of Cygwin + OpenSSH running on Windows Server 2008. I hope this helps!
Same issue on Windows 7 + OpenSSH (OpenSSH_6.5p1, OpenSSL 1.0.1f 6 Jan 2014) while running C# program connecting Access database.
I've added
export CommonProgramFiles="C:\Program Files\Common Files"
in /etc/profile file.
Hope this help.

Resources