sql-server-2005

what is the best way to run Sql Agent job using C#?

僤鯓⒐⒋嵵緔 提交于 2020-01-03 04:47:29
问题 I am using Sql server 2005 and using C#/Asp.Net 4.0 for UI. I want to trigger the sql job from an user action in a webpage. I need to keep checking job's status while its running. There are several old threads on this issue which gets the status of the jobs (How to monitor SQL Server Agent Job info in C#) but i need my program should be able to Run,Stop,Enable,Disable the jobs I need the below functionality in my UI. Check the status of a sql job Run the specified job Stop the job Disable

Efficient query for finding duplicate records

安稳与你 提交于 2020-01-03 04:33:06
问题 I need to query a table for duplicate deposit records, where two deposits made at one cash terminal, for the same amount, within a certain time window, are considered duplicate records. I've started working on a query now, but I would appreciate any advice or suggestions on doing this 'properly'. 回答1: Generally, you'd do a self join to the same table, and put your "duplicate" criteria in the join conditions. E.g. SELECT * FROM Transactions t1 inner join Transactions t2 on t1.Terminal = t2

Restore database in SQL Server 2005

孤街醉人 提交于 2020-01-03 04:02:32
问题 BACKUP DATABASE [MPRM] TO DISK = N'\\rauf\shared\MPRM_15_5_10.BAK' WITH NOFORMAT, NOINIT, NAME = N'MPRM-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10 The backup process worked, and I got a file named MPRM_15_5_10.BAK in my shared folder ( D:\shared\ ). This is a backup created from another machine. When I try to restore the backup, using the following script RESTORE DATABASE [MPRM] FROM DISK = N'\\rauf\shared\MPRM_15_5_10.BAK' WITH FILE = 1, NOUNLOAD, STATS = 10 I get the

Convert to valid decimal data type

混江龙づ霸主 提交于 2020-01-03 03:46:32
问题 I have a column [Cash] nvarchar(50) that has data that will later be converted to decimal(9,3) during an import process,some of the data is consistent with normal looking numeric values such as 134.630,-80.662 and 324.372. Occasionally I have data with multiple dots for the numeric values such as 1.324.372 and -2.134.630. Is there a way of removing this extra dot. 回答1: declare @yourtable table(cash varchar(20)) insert @yourtable values('1.324.372') insert @yourtable values('-2.134.630')

Can I pass arguments to an external (CLR) SQL Server trigger?

戏子无情 提交于 2020-01-03 03:19:05
问题 I have a trigger in SQL Server, but I need to pass arguments to the CLR code, i.e., information not provided in the trigger context. Is something like this even possible? CREATE TRIGGER MyTrigger ON MyTable FOR INSERT AS EXTERNAL NAME MyAssembly.MyNamespace.MyTriggerHandler("Foo", "Bar") These arguments would be static, of course. The number of argument permutations is discrete, but creating a separate class or function in the CLR assembly for each would be unwieldy, and would require a

How to Split Time and calculate time difference in sql server 2005?

你。 提交于 2020-01-03 03:01:50
问题 i want to split the time and calculate time difference using sql server 2005 my default output is like this: EnrollNo AttDateFirst AttDateLast 111 2011-12-09 08:46:00.000 2011-12-09 08:46:00.000 112 2011-12-09 08:40:00.000 2011-12-09 17:30:00.000 302 2011-12-09 09:00:00.000 2011-12-09 18:30:00.000 303 2011-12-09 10:00:00.000 2011-12-09 18:35:00.000 I want my new output to be like this: Enroll No ..... FirtTime LastTime Time Diff 111 ..... 8:46:00 8:45:00 00:00:00 112 ..... 8:30:00 17:30:00 9

How to prune duplicate associations to yield a unique most-complete set

。_饼干妹妹 提交于 2020-01-03 01:51:26
问题 I hardly know how to state this question, let alone search for answers. But here's my best shot. Assume I have a table Col1 Col2 -----+----- A | 1 A | 2 A | 3 A | 4 B | 1 B | 2 B | 3 C | 1 C | 2 C | 3 D | 1 I want to find the subset of associations (rows) where: There are no duplicates in Col1 There are no duplicates in Col2 Every value in Col1 is associated with a value in Col2 So the above example could yield this result Col1 Col2 -----+----- A | 4 B | 2 C | 3 D | 1 Notice that A-4 must be

creating multiple users for a c#.net winform application using sql server express

怎甘沉沦 提交于 2020-01-02 18:05:32
问题 i have a single sql database in sql server express. i have a login MAINLOGIN, for this database. i want insertion of data in this database through multiple users, U1,U2,U3, each having different userids & passwords. These users would be created by MAINLOGIN , manually or via the winform application. So while creating MAINLOGIN , i would give him permission to further create logins. For this what should i do? i cannot create MULTIPLE users, because for one database, only one user can be

SQL Server 2005 - Trigger Loop?

廉价感情. 提交于 2020-01-02 17:34:08
问题 I am using triggers for the first time. If I update a field in a table by an update trigger on the same table, with this spark a loop? Does sql server guard against this recursive behavior? Thanks 回答1: This page (search for RECURSIVE_TRIGGERS ) describes some of the database settings you can use to modify this behavior. Also, one way to safeguard your procedures is to use either the UPDATE() function or the COLUMNS_UPDATED() function. If, for example, you have a table with columns A , B , and

Retrieving the an SQL Agent job's specific error

♀尐吖头ヾ 提交于 2020-01-02 13:16:14
问题 I am using msdb..sp_help_job to access whether a job succeeded or failed and can retrieve a general error. But, I want to access the specific error for the step that failed. I cannot seem to find it. It is not in this list of helpful stored procedures provided by MS http://msdn.microsoft.com/en-us/library/ms187763%28v=SQL.100%29.aspx The account running the query is limited but does have the SQLUserAgent role and owns the Jobs that it is accessing. 回答1: try using sp_help_jobhistory (Transact