close/kill transaction

You should first figure out what it was doing, where it came from, and if applicable how much longer it might be expected to run: SELECT r.[session_id], c.[client_net_address], s.[host_name], c.[connect_time], [request_start_time] = s.[last_request_start_time], [current_time] = CURRENT_TIMESTAMP, r.[percent_complete], [estimated_finish_time] = DATEADD ( MILLISECOND, r.[estimated_completion_time], CURRENT_TIMESTAMP ), current_command = SUBSTRING ( t.[text], r.[statement_start_offset]/2, COALESCE(NULLIF(r.[statement_end_offset], -1)/2, 2147483647) ), … Read more

How to set the default schema of a database in SQL Server 2005?

A default schema is user-specific: USE yourDatabase; ALTER USER [yourUser] WITH DEFAULT_SCHEMA = myschema; More information about the ALTER TABLE for SQL 2005 might help you as well. As this is user-specific, if you have multiple users, you will need to execute this query (on each database) for each user whose default schema you want … Read more

conditionally create user in SQL Server

You can consult the two system catalogs sys.server_principals to check for server logins, or sys.database_principals in your specific database for users of your database: use myDB GO if not exists(select * from sys.database_principals where name=”foo”) — create your database user if not exists(select * from sys.server_principals where name=”foo”) — you need to create a server … Read more

Unable to cast TEXT to XML in SQL Server

Your problem is: you have XML with an encoding=”utf-16″, but your column is a non-Unicode column…… Assuming that you cannot change it to NTEXT either, you have to do two nested CAST to achieve what you’re looking for: SELECT CAST(CAST(XML AS NTEXT) AS XML).value(‘(/Record/UserGuid)[1]’, ‘NVARCHAR(max)’) FROM tbl_Module_RequestForms_Items First, you need to cast to NTEXT (or … Read more

Change datatype varchar to nvarchar in existing SQL Server 2005 database. Any issues?

Note that this change is a size-of-data update, see SQL Server table columns under the hood. The change will add a new NVARCHAR column, it will update each row copying the dta from the old VARCHAR to the new NVARCHAR column, and then it will mark the old VARCHAR column as dropped. IF the table … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)