SQL Errors – AumTechHub.Com http://aumtechhub.com Just share it!!! Tue, 23 Nov 2021 01:45:18 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.2 179596041 Database Mail Error Failed to initialize sqlcmd library with error number -2147467259 http://aumtechhub.com/database-mail-error-failed-to-initialize-sqlcmd-library-with-error-number-2147467259/?utm_source=rss&utm_medium=rss&utm_campaign=database-mail-error-failed-to-initialize-sqlcmd-library-with-error-number-2147467259 Wed, 11 Aug 2021 03:29:26 +0000 https://aumtechhub.com/?p=249 In this example below the error will occur because the context of the query is running under MSDB when the query is specified without the database name in the query.

The correct query for the above example is:

EXEC msdb.dbo.sp_send_dbmail
@profile_name ='dbMail',
@recipients = 'dharmyog.com@gmail.com',
@subject ='Test Email',
@body ='Test Email',
@query=' select * from [dbo].[vwEmployees] Where EmployeeAge = 25',
@attach_query_result_as_file = 1;

EXEC msdb.dbo.sp_send_dbmail
@profile_name ='dbMail',
@recipients = 'dharmyog.com@gmail.com',
@subject ='Test Email',
@body ='Test Email',
@query=' select * from EmployeeDB.dbo.vwEmployees Where EmployeeAge = 25',
@attach_query_result_as_file = 1;

This way the stored procedure will execute under the msdb context and the query will execute because the database hierarchy is referenced. So the database name has to be entered in the query.

]]>
249
How to fix DBCC errors? http://aumtechhub.com/fix-dbcc-errors/?utm_source=rss&utm_medium=rss&utm_campaign=fix-dbcc-errors Wed, 26 Aug 2020 00:01:06 +0000 http://aumtechhub.com/?p=27 How to repair your database when you get DBCC errors.

Put the database in single user mode.

ALTER DATABASE YourDBName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

Go;

Then run the following code:
DBCC CHECKDB(N'YourDBName', REPAIR_ALLOW_DATA_LOSS);

Then put the database back in multi-user mode.

ALTER DATABASE [YourDBName] SET MULTI_USER;

Go;

]]>
27