sql-server-2008

sql db problem with windows authentication

Have a SQL Server 2008 db which I connect to the Windows Authentication .. has worked good for 7-8 months .. but now when I come to work today it no longer worked to connect, without that I had done something Error message was: Can not open user default database. Login failed. Login failed for user 'Jimmy-PC \ Jimmy'. where the first...

SQL Server - Test the result of a stored procedure

In SQL Server, it is possible to test the result of a stored procedure to know if the result return rows or nothing ? Example : EXEC _sp_MySp 1, 2, 3 IF @@ROWCOUNT = 0 BEGIN PRINT('Empty') END ELSE BEGIN PRINT(@@ROWCOUNT) END But @@ROWCOUNT always return 0 so maybe is there another way of doing this ? ...

SQL Server - In clause with a declared variable

Let say I got the following : DECLARE @ExcludedList VARCHAR(MAX) SET @ExcludedList = 3 + ', ' + 4 + ' ,' + '22' SELECT * FROM A WHERE Id NOT IN (@ExcludedList) Error : Conversion failed when converting the varchar value ', ' to data type int. I understand why the error is there but I don't know how to solve it... ...

speed up sql INSERTs

I have the following method to insert millions of rows of data into a table (I use SQL 2008) and it seems slow, is there any way to speed up INSERTs? Here is the code snippet - I use MS enterprise library public void InsertHistoricData(List<DataRow> dataRowList) { string sql = string.Format( @"INSERT INTO [...

Determining SQL MERGE statement result

Is there a way to determine whether a record was matched or not (whether the record was inserted or updated) after calling MERGE? Ideally I'd like to output it to a parameter. Edit: I've got the merge statement outputting what happened in my management studio using the following statement: Say I had the following merge statement: MERG...

SQL Server stored procedure line number issue

Hello everyone, I am using SQL Server 2008 Enterprise. I met with issue which says line 9 of stored procedure foo is meeting with dead lock issue. My question is how to find exactly the 9th line of the stored procedure? My confusion is because of coding format issue, how to locate 9th line correctly. thanks in advance, George ...

SQL Server deadlock issue

Hello everyone, I am using SQL Server 2008 Enterprise. I am wondering whether dead lock issue is only caused by cross dependencies (e.g. task A has lock on L1 but waits on lock on L2, and at the same time, task B has lock on L2 but waits on lock on L1)? Are there any other reasons and scenarios which will cause deadlock? Are there any ...

SQL Server 2008 management studio drop tables warning?

Why does SQL server 2008 always warn about needing to drop tables to rename columns? I was under impression this was not required unless it was a key. If I change a column from null to not null even if is not a key field it wants to drop table and all relations. ...

I can't insert NULL values into datetime2 fields in SQL Server

Hi! I'm using CakePHP. When trying to insert a null value into a field it turns into 1900-01-01 00:00:00. Here's a sample of my code: $this->save(array( 'date_signed' => null )); What seems to be the error and how do I fix it? Thanks in advance! ...

MS SQL Specific Tables Hanging at Queries

I have SQL Server 2008. I run a query in a table on a database. The weirdest thing keeps happening. I run a simple select statement on the table. I know there are 62 rows in the table but it gets stuck at row 48 and goes on "querying...". Waited already for hours and it didn't move on from there. I only know of two programs, and on...

Is it possible to get all triggers associated with a table using sql server 2008 clr programming?

Hi All, Is it possible to use .net (C# SQL CLR) to find all the triggers associated with a table? And also will I be able to determine the type of that trigger? - CLR or T-SQL? Thanks, Chaks ...

Disable Primary Key and Re-Enable After SQL Bulk Insert

I am about to run a massive data insert into my DB. I have managed to work out how to enable and rebuild non-clustered indexes on my tables but I also want to disable/enable primary keys as I believe this will speed up the insertion process. NOTE: This is over numerous tables and so I assume I need some loop to get the primary key info...

Return dataset in dataflow

Hi All, Could I get ideas on retrieving the dataset using lookup method. Basically, my scenario as I have source data needs to lookup for other source table and on matching column from source I need to get all the records from other source data. its a one to many relations. I tried Lookup but gives only one record on matching condition...

Why does ROW_NUMBER OVER (ORDER BY column) return a different result order than just ORDER BY column?

I'm on SQL Server 2008, using NHibernate as persistence layer (although this problem is purely SQL, I believe). I've boiled down my problem to the following SQL statement: SELECT TOP 2 this_.Id as Id36_0_, this_.Name as Name36_0_, ROW_NUMBER() OVER (ORDER BY this_.IsActive) as MyOrder FROM Campsites this_ ORDER BY this...

Reporting Services - can't group by a column called "LanguageId"

Folks, I have a really odd behavior here: I have a SQL Server 2008 Reporting Services report which gets grouped and sorted dynamically. One of the column in my data set which I display is called LanguageId and I was trying to get a grouping going by this LanguageId field. I checked, double-checked and triple-checked the data being retur...

DBConcurrencyException in winforms app due to munged time portion of datetime field

Hey All, I've got a winforms .net 2.0 application that's hitting a MS SQL 2008 server. I load up a DataSet from that server, expose a bunch of that dataset via bound winform controls & then push updates via SqlDataAdapters. One such adapter is attached to a table w/two key fields RecruitID and StatusDate. StatusDate is a DateTime fie...

Store and retrieve html from sql server 2008 and display using ASP.NET MVC?

Hi all, I am trying to store HTML and hyperlinks in my SQL server 2008 database. I want to also be able to display the hyperlinks and render the HTML accordingly. I am trying to do this in ASP.NET MVC, so I tried using the HTTPUtility.HtmlEncode() method, but didn't really store it the way I wanted. So can anyone please guide me through...

Export a data table in CSV format sql server 2008

I need to create a stored procedure which queries a table and creates a CSV file for that data in a specified directory location. how do i do it? ...

SHA256 in T-sql stored procedure

Is it possible to generate a SHA-256 hash of a string from a stored procedure in Sql Server 2008? For deployment reasons, I'd prefer it in TSQL. ...

How can i look at executed queries?

Hello, can anyone tell me how to view executed queries in SharePoint? I couldn't find a way to show query logs with SQL Server. As you know, SharePoint framework hides all queries from programmers. I would like to look into the queries and understand the mechanisms. http://www.infoq.com/articles/SharePoint-Andreas-Grabner In above arti...