EXEC sys.sp_expired_subscription_cleanup throwing error Msg 18482, Level 14, State 1, Line 1Could not connect to server 'DEV1' because 'DEV2' is not defined as a remote server. Verify that you have specified the correct server name. .
↧
EXEC sys.sp_expired_subscription_cleanup
↧
Schedule SSIS Package on Cluster with failover
I am trying to schedule an SSIS package on Microsoft SQL Server cluster with a failover but don't know the how or the best approach. Currently the package works in a single node. I will appreciate if someone can point me to step by step approach to achieve this
↧
↧
Isolation level inside stored procedures
Dear all,I have this stored procedure that has inside:SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTEDThe goal is to decrease the isolation level to the lowest possible. It seems to be working fine. but what about the stored procedures that are called from inside others? i.ecreate SP1 Name1 ()asbeginSET TRANSACTION ISOLATION LEVEL READ UNCOMMITTEDexec SP_2endIn the above situation the SP2 does not have a direct mention inside is code to the SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED but because it is called from inside a SP that has this SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED will it also run with this isolation level?thanks
↧
CMDExec Proxy account not working with Domain Service Account...
I'm working on migrating an existing Server 2003 / SQL 2005 system to Server 2008 R2 / SQL 2008 R2, and am having some problems getting a proxy account to work. The account is needed to execute some OS operations, NOT to affect DBs on the server. Things like unzipping files that are recieved to a particular folder and deleting the files when done.The SQL Agent is running using a domain account for this purpose. There's also a domain-level account for the proxy account.I've added the Proxy account to the SQL Logins, created a Credential for it, then created the Proxy in Agent. I've granted the appropriate users access to the Proxy (the "Principals" section), and assigned the proxy to execute a step in a test job (dir e:\)Now, the problem.It fails.If I run the step using the Agent account, it works. If I set the Agent to use the "Network Service" account and the proxy, it works. If I set the Agent to use the domain account and the job to use the proxy account, it fails with:"Executed as user: domain\svcaccount. The process could not be created for step 1 of job 0x2E0030DE6B7C444E8C0E4759A405B8E5 (reason: A required privilege is not held by the client). The step failed"I have verified the proxy account does have access to the E:\ drive by running a command prompt as the account. I also "cloned" the local group membership for the proxy from the Server 2003 system, so it belongs to the local Admins account.I've looked through the Windows Security log, and it shows it to be logging in OK. I see a logon event with a subject account name of the Agent service account, and a new logon security ID of the Proxy account. So it seems the impersonation is working...Any thoughts?
↧
How to avoid this message : 'Database name 'tempdb' ignored, referencing object in tempdb.'
Hi,How to avoid this message? I tried to fix this but no luck.----------------------- Warning ---------------Database name 'tempdb' ignored, referencing object in tempdb.Database name 'tempdb' ignored, referencing object in tempdb.-------------------------------------------------------------[code="sql"]SET NOCOUNT onIF OBJECT_ID('tempdb..#members_roles') IS NOT NULL--IF 0 < OBJECT_ID('tempdb..#members_roles') DROP TABLE tempdb..#members_rolesDECLARE @cmd AS NVARCHAR(MAX) = N'';DECLARE @login_name AS NVARCHAR(1000) = 'XYC';DECLARE @RoleName AS NVARCHAR(1000)CREATE TABLE tempdb..#members_roles( RoleName NVARCHAR(1000), MemberName NVARCHAR(4000), )INSERT INTO tempdb..#members_roles(RoleName, MemberName)SELECT --a.role_principal_id, role.name AS RoleName, --a.member_principal_id, member.name AS MemberNameFROM sys.server_role_members aJOIN sys.server_principals AS role ON a.role_principal_id = role.principal_id JOIN sys.server_principals AS member ON a.member_principal_id = member.principal_idWHERE member.name = @login_name;SELECT * FROM #members_rolesdeclare c cursor for SELECT RoleName FROM tempdb..#members_rolesopen cfetch next from c into @RoleNameWHILE @@FETCH_STATUS = 0 BEGIN SELECT @RoleName--SELECT @cmd = @cmd + 'SET @cmd =' ALTER SERVER ROLE '+@RoleName+' DROP MEMBER '+ QUOTENAME(LTRIM(RTRIM(@login_name))) +';'SELECT @cmd--exec sp_executesql @cmdEXEC(@cmd);fetch next from c into @RoleNameENDclose cdeallocate cSET NOCOUNT OFF[/code]
↧
↧
Check all the users have running profiler trace permission
Hello,Granting the permission to run trace is simple, but if I need to check who all users have executing profiler trace, how to do that by running a simple t sql?
↧
Display 5 records each time from a table sql script
Hi ExpertsI want to display 5 records each time from a column until all records are touched in the table.Can you suggest a easy script to achieve it.Note: if incase in the table the total number of records are less than 5, it will display all records based on the count
↧
Restore from a backup with a wildcard ??
I have a backup that comes to me nightly in the format of XXXX_YY_MM_DD.bakwhere the date is incremented each night the previous night backup is deleted when the next days is added so in general I have only one in that folder. I wanted to setup a restore to run nightlyRESTORE DATABASE [XXXData] FROM DISK = 'C:\folder\ExtractedData\app_XXX_backup_15_01_28.bak' --location of .bak fileWITH REPLACEI would like to do something like RESTORE DATABASE [XXXData] FROM DISK = 'C:\folder\ExtractedData\[b]app_XXX_backup*.bak' [/b] --location of .bak fileWITH REPLACEWhile I'm asking.. In case there is an older one left behind(which shouldn't happen) I saw something about "LATESTFULL" but think its a redgate command?Thanks in AdvanceJoe
↧
how to make a query for series of records ?
[code]WeekNo FromDate ThruDate Period36 2016-08-29 2016-09-04 20160937 2016-09-05 2016-09-11 20160938 2016-09-12 2016-09-18 20160939 2016-09-19 2016-09-25 201609[/code]i want to make a series of record like this [code]WeekNo Date Period36 2016-08-29 20160936 2016-08-30 20160936 2016-08-31 20160936 2016-09-01 20160936 2016-09-02 20160936 2016-09-03 20160936 2016-09-04 20160937 2016-09-05 20160937 2016-09-06 20160937 2016-09-07 20160937 2016-09-08 20160937 2016-09-09 20160937 2016-09-10 20160937 2016-09-11 20160938 2016-09-12 201609.... etc[/code]is it possible create a query using recursive cte ?i need a help from expert..thank u..
↧
↧
Auto Rollback tran ?
Can SQL SSMS do an Auto Rollback of a transaction? I had an SQL Update done under Begin tran block.And then I didn't commit it, but wanted to check the table entries in the same session. But that query had an error in it. As a result of which i realised that the Update was rollbacked.Bij.
↧
Tracking Records Insertion Count
Here in the below procedure we are taking some data from temp data and inserting into main table.Every time the package runs it will insert the records which are not exists in the main table from temp table.Inserts are being done in loop here.In the same procedure we are inserting errors into error table as well as tracking the insertlog count(No of records inserted).Now I want to change this logic..I am expecting to create a package where it first truncates temp table and loads from source(temp) to destination(main table) and last this procedure will do a consolidate task (Call below Procedure)where it insert the records which are not exists in the main table from temp table.Before this procedure i want to add one execute sql task which will do log insert(success) itand load log error (if it fails) Instead of doing both log insert and log error(same stuff) in the below procedure. Mainly i want to separate it with different stored procedures one for log insert and one for to capture errors.CREATE PROCEDURE CONSOLIDATESET NOCOUNT ONDECLARE @Employee,@EmpCode,@NoOfRecsInserted INT,@Error INTSET @NoOfRecsInserted = 0DECLARE ACursor CURSOR STATIC FORSELECT Employee FROM dbo.EmpTempwhere --bla bla (filtering the records) OPEN ACursor FETCH NEXT FROM ACursor INTO@Employee WHILE @@FETCH_STATUS = 0BEGIN SET NOCOUNT ON INSERT INTO dbo.Emp (Employee) VALUES(@Employee) SET @Error = @@Error IF @Error <> 0 BEGIN SET NOCOUNT ON SELECT 'EmpCode' + CAST(@EmpCode AS VARCHAR(50)) SET NOCOUNT ON INSERT INTO dbo.ErrorTable(StoreProcName,ProcessName,KeyValue,Error) VALUES ('dummy','dummy','@EmpCode',@Error) EXEC dbo.Exception @Employee END IF @Error = 0 BEGIN SET @NoOfRecsInserted = @NoOfRecsInserted + 1 END FETCH NEXT FROM ACursor INTO @EMployeeENDCLOSE ACursor DEALLOCATE ACursor -- Insert audit rows into LogCount tableEXEC dbo.ILogCounts 'TableName',@NoOfRecsInserted,0,0,'Blabla'---------------------------------------------------------------------------------------------------ALTER PROCEDURE [dbo].[ILogCounts]@Name varchar(30),@InsertCount int = null,@UpdateCount int = null,@DeleteCount int = null,@ScrName varchar(100)ASINSERT INTO dbo.LogCounts(Name,InsertCount,UpdateCount,DeleteCount,ScrName,CreatedDate)VALUES(@Name,@InsertCount,@UpdateCount,@DeleteCount,@ScrName,getdate())Here in the LogCounts stored procedure how can i track the no of records inserted? I mean insert count.I want to keep this stored procedure(Logcounts) in the execute sql task before the consolidate process(CONSOLIDATE PROCEDURE)
↧
How do I initialise a sql variable to 0 in stored-procedure ?
Dear friends ,How to initialise a sql variable to 0 in stored-procedure which would work both in SQLServer 2005 & 2008 ?
↧
When Is an Execution Plan Cached?
TL;DR: when does an execution plan get a)cached b) cleared from the cache?As part of a continual improvement process I'm looking into the run times of various reporting stored procs with a view to establishing which of the frequently run procs take the longest. I've found various scripts to get execution times by looking at sys.dm_exec_procedure_stats. When I linked these scripts to the reporting procs though, I found some gaps. By this I mean that there was a proc associated with a report but my execution time query didn't return a proc name. I then did a bit of searching and I found a post by some guy called Jeff Moden who pointed out that these scripts worked by querying the plan cache. Therefore if there was no plan in the cache, there would be nothing to return. This is where I did get stumped. There doesn't appear to be any pattern to what procs are returned by the query. One of the procs is with OPTION(RECOMPILE), that makes sense to me. If it's recompiled each time, there will be no point in caching a plan (I'll stand corrected on this, but it is a logical explanation to me) . Others are called from SSRS as a text dataset using 'EXEC Proc @parameter'. I can see why this wouldn't get cached. There are bits of ad hoc SQL to establish dates and users etc.; again I can see why these aren't cached. Others are less easy to explain. They appear to be pretty simple queries with a handful of joins and no variables. Other procs were run before them and they are returned by the execution time query so it doesn't look like they were 'aged out'. What I know about the plan cache can be written on the back of a stamp so could somebody point me at a decent link to find out a bit more?
↧
↧
how to convert navarchar to datetime
i have column senddate as "2016-08-10 05:29:27" as nvarchar (4000) destination is datetime.how do i convert this to datetime.convert(datetime,CAST(SendDate as datetime),112) but appends 000 at lastlike '2016-08-10 05:29:27.000' do not need 000 at last
↧
While trying to run DBCC CHECKDB Getting error - "Msg 845, Level 17, State 1, Line 1 Time-out occurred while waiting for buffer latch type 3 for page (1:16695257), database ID 46."
Hi,I am using Ola's script to one of the Sharepoint databases to run checkDB. It's SQL Server 2008 R2.https://ola.hallengren.com/sql-server-index-and-statistics-maintenance.htmlFailing against one of the databases - and getting this error:- "Msg 845, Level 17, State 1, Line 1 Time-out occurred while waiting for buffer latch type 3 for page (1:16695257), database ID 46."
↧
concurrency deadlock issue in SQL Server 2008 R2
Hello all -I'm having a concurrent deadlock issue, two batch jobs running simultaneously. Here is the backgroundSQL Server 2008 R2.During processing a stored proc updates a specific record in a table, thus the deadlock occurs between the two processesI Updated the database to allow committed snapshot and snapshot isolation:ALTER DATABASE xxxxx SET READ_COMMITTED_SNAPSHOT ON; ALTER DATABASE xxxxx SET ALLOW_SNAPSHOT_ISOLATION ON;Visual studio C# code around the stored proc call reads: using (var tscope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.Snapshot }))[b]The error log reads:[/b]An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Snapshot isolation transaction aborted due to update conflict. You cannot use snapshot isolation to access table 'dbo.yyyyyy' directly or indirectly in database 'xxxxxx' to update, delete, or insert the row that has been modified or deleted by another transaction. Retry the transaction or change the isolation level for the update/delete statement.The best I could come up with via internet research is the notion that I should set nonclustered indexes on the primary table, however the stored proc is not inserting anything into child tables, just doing a very basic update to the primary table.[b]Any idea how I can get around this, and allow the concurrent update to this table record between the two processes?[/b]Thanks in advance
↧
ODBC Error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'master..LoginInfo'
HII have a old ERP system that is using SQL server 2000. I wanted to upgrade to point to SQL server 2005. The system is using a super user that have ability to create database/users/tables etc. Somewhere during the installation is throwing an error when it querying a view to get the user info. on the query is using (..) notation instead of dbo ( that started on 2005). any workaround on the SQL server end to over come this? seem like 2005 doesn't support the .. notation below is the full error:Error: "" (1526)Program/Method: CNODBCMGR. SQLCOMMAND C:\PROGRAM FILES in DATALIB.VCTLine: 20ODBC Error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'master..PSILoginInfo'.IF (OBJECT_ID('master.dbo.v_psilogininfo') IS NOT NULL) SELECT sysl.name as UID, sysu.name, sysl.HasPW FROM master..v_PSILoginInfo sysl LEFT OUTER join PS11_0_W..sysusers sysu on sysl.sid = sysu.sid where sysl.name ='PSIUser_ADMIN' ELSE SELECT sysl.name as UID, sysu.name, sysl.HasPW FROM master..PSILoginInfo sysl LEFT OUTER join PS11_0_W..sysusers sysu on sysl.suid = sysu.suid where sysl.name ='PSIUser_ADMIN' (208)
↧
↧
Bulk copy from one database to another
Experienced developer but pretty new to SQL Server...About 8 times a year (roughly twice a quarter), I need to copy a subset of tables/columns from one database to another. This is due to data access security requirements over which I have no control (can't turn on cross database access). The copy involves ~ 1 billion records across 10 tables.Most of the source tables have no relationship (no FKs); 4 have FK's to another table. I've created indexes on the target tables to support the queries required by the application.My first attempt (TRUNCATE TABLE, INSERT INTO) filled the transaction logs. After a bit of Googling, I've written a Powershell script that uses the .Net Data.SqlClient.SqlBulkCopy class to copy the data from source to target database.When I tested the performance of this script copying to target heap tables, the results were great. Now that I've added the indexes, not so good.Any advice for improving the performance? Should I disable FK's, drop the indexes, truncate the tables, run the script, recreate the indexes, reenable the FK's? Is the *overall* processing time improved by first dropping the indexes, vs. just truncating the table and letting the indexes get recreated during the bulk copy? From my Googling, it doesn't appear that I can programmatically capture the current indexes and recreate them later. A pity, but this can be easily scripted.I just tested - it appears I have the access rights to change the target database logging mode.Any and all advice appreciated.
↧
Simple insertion for mutiple single code values
Hi Experts ,i need to insert below input_value into tableinput_value is: 'select cc_key ,'+ cast(@min_id as varchar(5)) + ',count(cc_key)cnt,''FAIL'' from cc_model_range_2_1 group by cc_key , created_date having created_date between '''+cast(@from_dt as varchar(10))+''' and '''+cast(@expt_dt as varchar(10))+''' and cc_key = '''+@cc_key+''' and count(cc_key) > 1'ex :table creation :create table ##multiple_code_values_insertion (raw_value nvarchar(max))select * from ##multiple_code_values_insertiontry to insert into table :insert into ##multiple_code_values_insertion values (''select cc_key ,'+ cast(@min_id as varchar(5)) + ',count(cc_key)cnt,''FAIL'' from cc_model_range_2_1 group by cc_key , created_date having created_date between '''+cast(@from_dt as varchar(10))+''' and '''+cast(@expt_dt as varchar(10))+''' and cc_key = '''+@cc_key+''' and count(cc_key) > 1'')
↧
Remove data - Please help
Hello, There are Table 1 and Table 2Table 1 - column A, B, C, DTable 2 - column A, B1, C1, D1I copied over the data to certain columns from table 1 to table 2update Table 2SET (B1, C1) = (SELECT B, CFROM Table 1WHERE Table 2.A =Table 1.A)--> data copied successfully so now both data has same data Here comes my question, now I have to remove the data from whatever I copied from table 1 to table 2 not delete the record. What should I do?thanks.
↧