sql-server

How to get the list of SqlInstances of a paricular machine

Can anyone tell me how to get remote Sqlserver instances using c# and SMO or any api? I have a remote server name "RemoteMC", which has 2 instances of sql server: "RemoteMc" and "RemoteMC\sqlexpress" I try to get the instances in code like this: Server srv=new Server("RemoteMC"); DataTable dt=SmoApplication.EnumAvailableSqlServer(true...

Why should I use int instead of a byte or short in C#

I have found a few threads in regards to this issue. Most people appear to favor using int in their c# code accross the board even if a byte or smallint would handle the data unless it is a mobile app. I don't understand why. Doesn't it make more sense to define your C# datatype as the same datatype that would be in your data storage sol...

Converting SQL2008 RDL file to SQL2005

How do I convert a RDL file that was created using the SQL2008 designer to work on SQL2005 Reporting services? ...

Trimming an array (filled via DBI)

Hello, I'm trying to read data from SQL Server database using Perl and the DBI module. My intention is to read the data and print it into a text file (comma separated). When I do this, I get the result like this: var1,var2,var3 40406,20 ,783 50230,78 ,680 50230,78 ,680 50230,78 ,680 50230,78 ,680 So there is a whitespace between the ...

SQL 2008 data types - Which ones to use?

Hi I'm using SQL Express 2008 edition. I've planned my database tables/relationships on a piece of paper and was ready to begin. Unfortunately, when I clicked on data type for my pkID_Officer I was offered more than I expected, and therefore doubt has set in. Can anyone point me to a place where these dates types are explained and exa...

DB won't reinitialize to local subscribers after Schema changes

First, I will outline my issue in case someone has an alternate fix. The Problem: I have a winform app that uses MergeReplication. This is working great except I needed to make changes to the columns and Primary Key on 5 Tables. I dropped them from the Articles and then made my changes. I then re-added them to the Articles and set t...

T-SQL, zero sum for no match on join

Hi All I have two tables, one with all my Branches, and one with all my sales. The sales table also contains a Sales Rep ID, a Branch ID, a month and a year. I need a query that will return the sum of a specific rep's sales for a year, grouped by branch and month, and the query must return 0 if there has been no sales in a branch for ...

Exception Access Violation in SQL

I'm having intermittent trouble with an OPENQUERY statement that pulls data through ODBC from a Progress database into SQL 2005. Most of the time it works, but every couple weeks, one of the many calls using this method bombs with a SQL Stack dump, shown below. We've run exhaustive hardware checks and also DB integrity checks, and have c...

SQL Server Table locks in long query - Solution: NoLock?

a report in my application runs a query that needs between 5 - 15 seconds (constrained to count of rows that will be returned). The query has 8 joins to nearly all main-tables of my application (Customers, sales, units etc). A little tool shows me, that in this time, all those 8 tables are locked with a shared table lock. That means, no...

SQL Server: How to make server check all its check constraints?

It seems that some scripts generated by Enterprise Manager* (or not, it doesn't matter) created check constraints WITH NOCHECK. Now when anyone modifies the table, SQL Server is stumbling across failed check constraints, and throwing errors. Can i make SQL go through all its check constraints, and check them? Running: sp_msforeachta...

Mass Renaming of Tables and Stored Procedures

I need to rename all of my tables, stored procedures and obviously the code within each stored procedure that was referencing the old table names. Why is the best way to do this? Some methods I have considered: SP_Rename - Gets half the job done. However this doesn't change the code within the SP itself In addition to RedGates' Refa...

How to use C# to get column's description of Sql Server 2005?

I can use " Microsoft.SqlServer.Management.Smo.Table " in C# to get a table columns of a Sql Server 2005 database. I have got the column.Name, but how can I get the column's Description in C#? I have saw the link: http://stackoverflow.com/questions/887370/sql-server-extract-table-meta-data-description-fields-and-their-data-types But ...

SQL Server 2005 summation query

Hi, I'm trying to create a query on SQL server 2005 that will check if the sum of some fields in some detail records is equal to the total field in a header record. This will be used for creating electronic deposit of checks for the company I'm working for. The hierarchy looks like this: Deposits --> Batches --> Checks Before creatin...

Writing a query to get all records in a group based on an item in the group

Sorry for the unhelpful title, but hopefully I can explain this well enough. Lets say I have three tables, Item ItemKey ItemName Group GroupKey GroupItem GroupKey ItemKey Given an ItemKey, how would I get all records from the item table that belong to a group containing the item key? So if I have Item 1 ItemA 2...

SQL combining Union and Except

I want to union the result of two sub-queries (say SUB1 and SUB2). The sub-queries have multiple columns including an ID column. If an ID=1 exists in SUB1, I want the union result to include only the row of ID=1 from SUB1 and not include the ID=1 row from SUB2. eg. if SUB1 had the following columns and rows ID | Date 1 | 7/1 2 | 7/3...

MaxDB Data and Schema Export to SQL Server 2005/8

I am tasked with exporting the data contained inside a MaxDB database to SQL Server 200x. I was wondering if anyone has gone through this before and what your process was. Here is my idea but its not automated. 1) Export data from MaxDB for each table as a CSV. 2) Clean the CSV to remove ? (which it uses for nulls) and fix the date s...

Generate sql script of db/sprocs/etc. via command line

Hi, Is it possible to generate sql scripts for my sql server 2005/8 database via the command line? I want to automate the build process and part of it requires me to get the entire schema (tables/sprocs/etc) in a file. ...

How do I get a Windows Form client to update every time a SQL Server table changes?

I have a form with a list that shows information from a database. I want the list to update in real time (or almost real time) every time something changes in the database. These are the three ways I can think of to accomplish this: Set up a timer on the client to check every few seconds: I know how to do this now, but it would involve...

It's not refreshing/databinding the page. How to refresh linq datasource?

protected void DetailsView1_ItemInserted(object sender, EventArgs e) { using (SqlCommand cmd2 = new SqlCommand("uspUpdateDisplayHours", cn)) { cn.Open(); cmd2.CommandType = CommandType.StoredProcedure; cmd2.ExecuteNonQuery(); cn.Close(); } DetailsView1.DataBind()...

How to sort by number in SQL Server?

I have a table with a column stored as string, but it is really a number like this: 17 - Doe 2 - Mike 3 - James I need to sort them and create a output like this: 2 - Mike 3 - James 17 - Doe How to write the SQL? Thanks in advance! ...