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/
Related
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
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
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.
I have a database that I am able to access using plain ADO.NET using a connection string that contains a SQL Server Login's username and password. This is done in a WCF service running in IIS. The machine hosting the SQL Server instance is not the same machine as the one with the web service.
connectionString="Data Source=DB_MACHINE\SQLEXPRESS;Initial Catalog=MY_TEST_DB;Connection Timeout=120;User Id=my_web_user;Password=my_pass"
I'm writing some methods now that use SMO to see if tables and triggers exist.
I get the following error, which is strange becuase I'm not sure why it matters if the computer name has permission? I'm logging in using the SQL Server Login user name / pass I set up, so why does the error indicate the machine name. The statemetns are being executed by the web servcie which I believe is running under NETWORK SERVICE, but shouldn't it just be using the permissions of the SQL Server Login? And, how do I correct the problem? THe SQL Server Login can access the database when not using SMO.
Error generating report: System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: An exception occurred while executing a Transact-SQL statement or batch. (Fault Detail is equal to An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ----> System.Data.SqlClient.SqlException: The server principal "MY_DOMAIN\WEB_SERVICE_COMPUTER$" is not able to access the database "MY_TEST_DB" under the current security context.
at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
--- End of inner ExceptionDetail stack trace ---
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes exe...).
Well, as you mentioned you're using SMO, then you may try:
new ServerConnection("servername", "username", "password").ExecuteNonQuery(...)
It's good to know that by default WCF service is running under Application Pool dynamic user. Which is 'converting' to NETWORK SERVICE under the network based operations (e.g. connecting to databases) and then NETWORK SERVICE is seen as a machine user account e.g. mydomain\mypc$.
If you will not be able to connect as a user specified in connection string, then you can always add mydomain\mypc$ user as a database user and set appropriate privileges.
Keep in mind that SQL Server may not accept proper name of domain, e.g. mydomain.local.com\mypc$ may not be accepted, try then mydomain\mypc$.
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