sql-server-2008

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. ...

Updating a SQL table with CSV data?

I am trying to update one of my SQL tables with new columns in my source CSV file. The CSV records in this file are already in this SQL table, but this SQL table is lacking some of the new columns from this CSV file. I already added the new columns to my SQL table structure via ALTER TABLE. But now I just need to import the data from t...

How to increase MaximumErrorCount in SQL Server 2008 Jobs or Packages?

I have several jobs and several packages. In SQL Server 2005 we used to use DTS Packages, but they are now defunct (I know that I can re-enable them, but that's not what I'm after). I receive the following error by running one of my packages: Message: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeed...

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%...

Default instance name of SQL Server Express

I don't have access to a SQL Server Express installation at the moment, but I know that the installer usually installs SQL Server Express with an instance name. What is the default instance name for SQL Server Express installations? I.e., how do you access such an installation by default? Is it localhost\SQLEXPRESS$ ? Is the same name us...

'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...

ASP.NET MVC 2 - Trying to configure role/user management via ASP.NET Configuration Tool

First, my development environment: Win7 laptop with Visual Studio Professional 2010. IIS is NOT installed. I'm trying to turn on and set up some roles for user management via the ASP.NET Configuration Tool, as demonstrated in the MVCMusicStore tutorial. When I click on the 'Security' tab, I get the following error: "There is a proble...

Good practice to modify MSDB stored procs?

At work, we've working on SQL Server 2008 now, and my boss seems a little bit paranoid about security, so instead of having people be sysadmin (or whatever they need to be to own/modify jobs) he's been editing stored procs in MSDB (such as sp_update_job) and adding a role to the TSQL that checks for required permissions (such as adding S...

help with t-sql query

Hi Based on the below tables Table_A Id RelatedId --------------- 1 1 1 2 1 3 2 4 2 5 2 2 3 7 3 8 4 9 Table_B RelatedId Name -------------- 2 A 3 B I want to get all the rows from Table_A which have atleast one matching relatedid in Table_B. The Ids from Table_A that do not have match in Table...

ADO.NET Connection String

I have a SQL Server 2008 database that uses a default schema called "Arxame". How do I specify or change the default schema from "dbo" to "Arxame" in my connection string? I'm using C# and ADO.NET. ...

I Need Countries List in T-SQL

I have a Country table which has CountryName column. I need a ready made list in DDL to populate in the column CountryName. The table resides in SQL Server 2008. ...

How would you design a database for a comparison matrix

I am creating a comparison matrix and would like it to be dynamic. Take a look at this url: http://cmsmatrix.org/matrix/cms-matrix/1work This type of database design has really challanged me and every approach that i take to this may result in serious performance or maintenance issues. if you do not recommend a relational database for ...

DMF and DMV in SQL Server 2008

What are Dynamic Management Functions (DMF) and Views (DMV) in SQL Server 2005/2008 ? ...

User Defined Table Types Not Available

Do you need a specific version of Sql Server 2008 to have TVP (Table Value Parameters) or Table Types? I don't have the folder under types and I get an error when trying to create one: CREATE Type EntityTable AS TABLE (EntityId int ,EntityName varchar(max) ,EntityFriendlyName varchar(max) ,IconPath varchar(max) ,EntityDescription ...

SmoApplication.EnumAvailableSqlServers fails to return all servers

My application lists the available network SQL Servers using Return SmoApplication.EnumAvailableSqlServers(false) Until recently, I was running XP Pro, with SQL 2005, SQL 2008, and Visual Studio 2008. All worked perfectly, correctly listing the default SQL05 server, and the SQL08 named instance. I've now upgraded to Windows 7 x64, ...

Figuring out archiving or partition strategy?

We are using SQL Server 2008. Our requirement is this - We have about 4 tables related to transactions, which record orders placed by consumers, and their status of delivery.Once,the order is completed it has affect on inventory and finance. Now,these tables will become huge.So,we want to archive every 6-8 months.But,after archiving t...

Select / Insert version of an Upsert: is there a design pattern for high concurrency?

I want to do the SELECT / INSERT version of an UPSERT. Below is a template of the existing code: // CREATE TABLE Table (RowID INT NOT NULL IDENTITY(1,1), RowValue VARCHAR(50)) IF NOT EXISTS (SELECT * FROM Table WHERE RowValue = @VALUE) BEGIN INSERT Table VALUES (@Value) SELECT @id = SCOPEIDENTITY() END ELSE SELECT @id = RowID ...

Audit information on a relation table with NHibernate

I am using NHibernate on a project. The database is required to have creation date and creator user fields on relation tables but I do not want to map the relations to domains. My db design is like: school (id, name, credate, creuser) student (id, name, credate, creuser) school_student(id, school_id, student_id, credate, creuser) For ...

How to copy everything except data from one database to another?

Hi, In T-SQL (Microsoft SQL 2008), how can I make a new database which will have the same schemas, tables, table columns, indexes, constraints, and foreign keys, but will not contain any data from the original database? Note: making a full copy, then removing all data is not a solution in my case, since the database is quite big, and s...

SSRS runs report for 30 sec however it takes only 3 sec in SQL Studio...

SSRS report calls sproc from SQL 2008 and it takes 30 sec to render it. If I call the same sproc with the same params it takes 3 sec to finish. SQL server and SSRS are on the same box. What can I do about it? ...