sql-server

Using a trigger to simulate a second identity column in SQL Server 2005.

I have various reasons for needing to implement, in addition to the identity column PK, a second, concurrency safe, auto-incrementing column in a SQL Server 2005 database. Being able to have more than one identity column would be ideal, but I'm looking at using a trigger to simulate this as close as possible to the metal. I believe I h...

Finding the database name from tsql script

Is it possible to programmatically find the database context from a tsql script? ie the context that changes when you add a USE . I ask because I am not using a USE, and would like to find the database name the script is running on. ...

Add SQL query options to NHibernate query

I'm working with some code that generates ICriteria queries for NHibernate. They get executed using ActiveRecord and ActiveRecordMediator.FindAll() For certain queries, I need to optimise them by adding on an OPTION (HASH JOIN) hint at the end of the SELECT statement. Is there a quick way I can do this? I don't want to rewrite the qu...

"could not initialize a collection" + @Lob + MSSQL

When using Blob-fields in n-to-m-relations Hibernate and MSSQL are failing for some reason. SQL Error: 421, SQLState: S0001 The image data type cannot be selected as DISTINCT because it is not comparable. ... could not initialize a collection: [Dataset.documents#someID] My classes look as follows: @Entity class Dataset { @OneToMa...

SQL Server DateTime parameter 'rounding' warning

More of a warning than a question: We resolved a very puzzling bug this morning. We have a variety of reports that allow users to enter date ranges they want to run. The assumption is, if you ask for a report from 8/1/2010 to 8/10/2010 you meant to include 8/10/2010 so the end-date of the report isn't 8/10, it's something after that. I...

Third Party Tools for Monitoring SQL Server Performance

Hello, I'm in a situation where I came into a new job and I have to support several legacy systems. The original developer is no longer around. These legacy systems are really hammering away at our SQL Server and killing performance. I know that there are a lot of things that can be done in the code, but rewriting code is really my la...

How can I convert a string to a string encoded in UTF-8 and vice-versa?

A have a string %c3%ad which decoded with UTF-8 is í, but decoded with ASCII is Ã. I need to decode it using the UTF-8 encoding, how can I do that? Here is a select of the value and what it should be... SELECT ('%c3%81') as 'Á (81 = 129)', ('%c3%89') as 'É (89 = 137)', ('%c3%8d') as 'Í (8d = 141)', ('%c3%93') as 'Ó (93 = 147)', ('%c3%...

Create delimited string from a row in stored procedure with unknown number of elements

Using SQL Server 2000 and Microsoft SQL Server MS is there a way to create a delimited string based upon an unknown number of columns per row? I'm pulling one row at a time from different tables and am going to store them in a column in another table. ...

Calculations on Subquery in strong typed dataset

Hello, following background: i have a Table-valued Function that returns a Table that is a kind of filtered view(views can not be parameterised) on a large table. Now i need many row count values on different conditions. Is it possible to get all count values in one query without having to query this function for every condition? For th...

Creating a "date updated" column in MS SQL?

Is there any simple way to create a column in MS SQL that will track the last time a record was updated? I would like to have two fields. One to track when the record was created. That one is simple. Create a datetime field and set its default to getdate(). However the second field seams to be a bit more tricky. I want it to have the la...

how to configure hibernate config file for sql server

here is the config file for mysql <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property> <property name="hibernate.connection.username">root</property> <property na...

what is dynamic stored procedure ? what is their relation with dynamic functions and dynamic queries ?

how do we implement dynamic stored procedure and do they relate to dynamic functions and dynamic queries in sql server ? Kindly enlighten... ...

The transaction has aborted.

I have a multithreaded C# application where each thread has it's own set of db connections. Each thread uses TransactionScope / DTC. Sometimes, I get a "The transaction has aborted" exception. It's not from a timeout since it occurs in less than 2 seconds from starting the transaction. Here's the stacktrace: at System.Transacti...

converting a date from SQL Server to C# and then to javascript gives different results on US vs. London webserver

I have an asp.net mvc calendar application (using jquery ui datepicker) and i am running into a weird situation where when i test on a US webserver i see a certain date and when i test on a London web server i see a different date (the date before) Here are the details: I am storing a date in sql server as: 2010-09-16 00:00:00.000 ...

IIS Logs and Collaborative Filtering/Recommender System

I am trying to build a recommender system based on user clicks. so far, i am not very concerned with all the nodes. i just wanted a way to develop a mechanism to detect that when a user clicked on A, he clicked on B. and when the user clicks on B, he clicks on C. so basically, in this node: a > b > c Its not very important for me to be...

'datetime2' error when using entity framework in VS 2010 .net 4.0

Getting this error: System.Data.SqlClient.SqlException : The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. My Entity objects all line up to the DB objects. I found only a single reference to this error via Google: http://ramonaeid.spaces.live.com/blog/cns!A77704F1DB999BB0!182.entry Af...

Backing up Database AND replication configuration?

In SQLServer 2005, is it possible to migrate a database from a workstation to another and also take the Replication configuration with it? I mean, besides creating scripts. ...

Make SQL Server Express available from outer network

How to make my local SQL Server Express (which part of Visual Studio) available from outer network? ...

Migrating from custom user list to MS membership in SQL Server

Hello, Sorry, I'm not even sure how to ask this exactly... but I wrote a website with logins. For that, I made my own users and passwords tables and hashed the passwords myself. Now, I would much rather move to Microsoft's built in membership provider with asp.net in sql server. Does anybody know a good way to migrate over? The only re...

TSQL Table Transformation Fields => Columns

I have the following table layout. Each line value will always be unique. There will never be more than one instance of the same Id, Name, and Line. Id Name Line 1 A Z 2 B Y 3 C X 3 C W 4 D W I would like to query the data so that the Line field becomes a column. If the value exists, a 1 is applied in the field ...