sql-server

Are Programatic events possible in SQL Server

Scenario: An application is started, it connects to the DB and registers itself to listen for a specific event name. Then using either a trigger or stored procedure when certain criteria are met the event may be raised. The DB then notifies all the applications that have registered that they are listening for that event. The applicati...

SMO.Transfer and filestreaming

Has anyone managed to get the transfer mechanism working with FILESTREAM columns? My code is as follows: Transfer transfer = new Transfer(sourceDatabase); transfer.CopyAllObjects = true; transfer.DropDestinationObjectsFirst = true; transfer.CopySchema = true; transfer.CopyData = false; transfer.CopyAllTables = true; transfer.Options.W...

SQL Server 2008 Backup failes: BACKUP DATABASE is terminating abnormally

I have a stored procedure, which performs a database backup for a specific database. The problem is, it does work on one server and does not work on another server (the servers are on different machines). The backup drive is a local drive of the server. On the second server I get the exception "BACKUP DATABASE is terminating abnormally."...

Simple MS SQL count question

I have this SQL DECLARE @url varchar(100) SET @url = 'http://mysite.com/%' SELECT [UserSessionSequenceID] ,[SiteID] ,[Referer] ,[Timestamp] ,ROW_NUMBER() over (PARTITION BY [Referer] ORDER BY referer DESC) AS sort FROM [tblSequence] WHERE [Referer] IS NOT NULL AND [Referer] NOT LIKE @url AND siteID = 15 Want to c...

tray notification on database update

i want to build a little app that pops up a tray notification (or a toast popup or something) whenever an update or insert going into a certain table in a SQL server database. What is the simplest way of doing this as i want to avoid polling if possible? ...

Is it possible to query the system databases in SQL server without using the names?

When doing a query over several databases in SQL server (2005+) I find it sometimes necesary to exclude the system database (master, model, tempdb, msdb and distribution) Is there any OTHER way to filter these besides where name not in (''master', 'model', 'tempdb', 'msdb', 'distribution') I've looked at sys.databases and master.dbo...

Cannot open database "DBName" requested by the login. The login failed. Login failed for user 'MachineName\User'.

I created a web application but when trying to connect the DB I am getting this error Cannot open database "DBName" requested by the login. The login failed. Login failed for user 'MachineName\User'. I also tried adding that this user manually but it give error that this login already exist with different username..but it not shows in ...

SQL Server - How to insert into Varbinary(Max) column?

I have a table that looks as follows below. I don't really want to create a C# application to insert rows into this table, if I can avoid it, because of the VarBinary column. My intent is to store a Crystal report .RPT file in this column. Is there a T-SQL statement I can execute to insert/update rows into this table, and include an .RPT...

Problem in WHERE clause

So I have a query. It works if I comment out the part checking for the exclusion. WHERE H.BatchId = 3 AND H.IsExcluded != 1 IsExcluded is a bit field that accepts NULL values. All the values I'm selecting from are NULL, so that SHOULD be right. What am I doing wrong? It's returning no values the way it is, but if I comment out just ...

Is there a way to disconnect a Visual Studio 2008 Schema Compare from a database without closing the schema compare?

Let's say I want to (using Visual Studio) run a schema comparison between two databases, restore one of them from a backup, and run the schema comparison again. The schema comparison maintains a connection to the database, and SQL Server won't let me run the restore without removing all connections. Is there a way I can force the schema ...

How to separate this comma delim column to new table

Hello experienced SQL'rs... I've got a little issue (SQLServer 2005) that I've run into with a legacy table (I'm honestly not trying to cover my embarrassment here - it is an old table :-)). Basically, for reasons best known to the original coder, one of the columns is being used to record changes of state to the object referred to in t...

contains search over a table variable or a temp table

i'm trying to concatenate several columns from a persistent table into one column of a table variable, so that i can run a contains("foo" and "bar") and get a result even if foo is not in the same column as bar. however, it isn't possible to create a unique index on a table variable, hence no fulltext index to run a contains. is there ...

Create a DATABASE using as a Name from a Variable

I would like create a database using value from a variable. Here my script but it does not work. Any ideas? -- Set Data Base name DECLARE @DataBaseName char(64); SET @DataBaseName = 'DbCmsWebsiteTest'; -- Create Data Base CREATE DATABASE @DataBaseName; GO ...

SQL Server2008: BeginExecuteNonQuery / EndExecuteNonQuery Problem

I have a stored procedure, which writes a backup of a specific database. I call this SP in a C# / Windows Forms application asynchrounously. Here is the code snipped: IAsyncResult result = command.BeginExecuteNonQuery(); while (!result.IsCompleted) { System.Threading.Thread.Sleep(1000); ... } command.EndExecuteNonQuery(result)...

How to separate this field into two columns

Hello again fellow sql'rs, I've got a seamingly simple problem to solve that normally would be fairly easy. I've got a field that contains a DateTime portion, as well as a trailing text portion. I now need to split this field into two discrete fields - DateTime and Varchar. Now for the little gotcha. The data has been saved with two dif...

Unique Index Error when creating non-unique index - SQL Server

I trying to and a non-unique index to a table table in SQL Server 2005. I am getting the following error when I try to create it. Msg 1505, Level 16, State 1, Line 1 The CREATE UNIQUE INDEX statement terminated because a duplicate key was found for the object name 'dbo.oe_pick_ticket' and the index name 'idx_pick_ticket_popup_wmms...

Stored procedure times out when ran from code, but not from query tool

I am trying to figure out why a stored procedure call takes seconds in a SQL server express query window, but when I run call the stored procedure in code the query TIMES OUT. We are using sql server 2008. I know it is hard to say exactly what is going on without seeing the stored procedure. I'm just hoping this is a known issue. Any...

Is it possible to get the mac address using a stored procedure?

Was wondering if it was possible to get the mac address of the server using a stored procedure? I did some searching for a while but found nothing. This is using SQL2008. Update Unfortunately the answer that uses newsequentialid() can return the wrong MacAddress if there is VMWare on the server. ...

Have XML file need it to populatemultiple SQL Tables

I have a XML file that I need to populate multiple SQL tables, and I was wondering what the best way to do that is. I was thinking dataset, or xslt but I honestly not sure. Here is my generated XML (part of it) <?xml version="1.0" encoding="utf-8" standalone="yes" ?> - <!-- Created: 8/3/2010 12:09:15 PM --> - <Trip> - <TripDetail...

optimizing a view for hierarchical data

I currently have a query that contains a self-join to query all the direct and indirect managers of an employee from a table that stores company organization info using the nested sets model. In this SQL notation, numbers preceded by a colon (e.g. :1) are variables: select parent.empid, parent.depth from RelationshipMgr as node join Re...