Skip to main content

Posts

Showing posts from 2014

sp_msforeachtable - Quick counting table rows

i just starting to play along with SSIS and SSAS and i came up with this trick to show wether my data has been populate into staging or data warehouse table so here is the script EXEC sp_MSForEachTable " DECLARE @count AS INT SET @count=0 SELECT @count = ISNULL(SUM(1), 0) FROM ? PRINT ""?: "" + CONVERT(VARCHAR, @Count) , @whereand = "ORDER BY 1" "  until then

sp_msforeachtable - Delete data in all tables in SQL Server database

hi all, just remember to post this useful tips -- disable all constraints EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all" -- delete data in all tables EXEC sp_MSForEachTable "DELETE FROM ?" -- enable all constraints exec sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all" --if some of the tables have identity columns we may want to reseed them EXEC sp_MSforeachtable "DBCC CHECKIDENT ( '?', RESEED, 0)" see u then

sp_MsForEachTable - compare data between tables

usually i will using temporary table to build dynamic query to compare the value for two indentical database between two servers but few weeks ago i know undocumented sp_msforeachtable stored procedure and gain some advantage for using it exec sp_MSforeachtable  @command1 = ' IF EXISTS( SELECT top 1 * FROM [server2].db_name.? EXCEPT  SELECT top 1 * FROM ?   ) PRINT ''?'' ' just make sure u use "." in first syntax because sp_msforeachtable return "dbo.table_name" for parameters reference please see this link see u

create ClickOnce shortcut at Startup

currently there are needs to add some shortcut based on ClickOnce Application that being deployed, it's obvious we can't create it manually because of the installation path here is some remedy :D, u need to add reference to System.Deployment, System.IO,  System.Reflection  if (ApplicationDeployment.IsNetworkDeployed) { string publisherName = ((AssemblyCompanyAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute), false)).Company; string productName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); startupPath = Path.Combine(startupPath, productName) + ".appref-ms"; if (!File.Exists(startupPath)) { string allProgramsPath = Environment.GetFolderPath(Environment.SpecialFolder.Programs); string shortcutPath = Path.Combine(allProgramsPath, publisherName); shortcutPath = Path.Combine

Find all Database size in SQL Server

hi, just came across a very good script from Pinal Dave u can see all database information in one place here the script SELECT database_id, CONVERT(VARCHAR(25), DB.name) AS dbName, CONVERT(VARCHAR(10), DATABASEPROPERTYEX(name, 'status')) AS [Status], state_desc, (SELECT COUNT(1) FROM sys.master_files WHERE DB_NAME(database_id) = DB.name AND type_desc = 'rows') AS DataFiles, (SELECT SUM((size*8)/1024) FROM sys.master_files WHERE DB_NAME(database_id) = DB.name AND type_desc = 'rows') AS [Data MB], (SELECT COUNT(1) FROM sys.master_files WHERE DB_NAME(database_id) = DB.name AND type_desc = 'log') AS LogFiles, (SELECT SUM((size*8)/1024) FROM sys.master_files WHERE DB_NAME(database_id) = DB.name AND type_desc = 'log') AS [Log MB], user_access_desc AS [User access], recovery_model_desc AS [Recovery model], CASE compatibility_level WHEN 60 THEN '60 (SQL Server 6.0)' WHEN 65 THEN '65 (SQL Server 6.5)' WHEN 7

Force Application update in ClickOnce deployment

the key is to set minimum requirement version to be exactly like the one u published right now to remove the update popup dialog when starting clickonce program just make sure the version is the same between Publish version and Update the Project properties - Publish until then

WCF: The underlying connection was closed

hi, just got an error for couple of days when try to return a model contain child record using Entity Framework and DBContext i have this Role class that contain list of User within that Role so when i try to get specific Role along with the User it give me an error "The underlying connection was closed " after searching alot i came up with this great solution disabled proxy creation and lazy loading or  manually in Entity DBContext constructor it run succesfully and can return UserInRole but if i filled up the table then the error comes, so we need to  Preserving Object Reference in WCF  but i came with this very useful  Andrey Chabster Blog  that using custom attribute that needed for the Service contract and Operation contract  until then

The version of SQL Server in use does not support datatype datetime2

hi again,  just came up with this error in Entity Framework  the reason is because my development using SQL2008 express edition but the preproduction using SQL2005 and the solution is fairly simple  Open your EDMX in a file editor (or “open with…” in Visual Studio and select XML Editor). At the top you will find the storage model and it has an attribute ProviderManifestToken. This has should have the value 2008. Change that to 2005, recompile and everything works after trying up for 2 hours :D until then

Renaming SQL Server Default Instance

hi all, found another intresting stuff to post scenario: u change windows computer name and suddenly the query that contains SQL Server link server or anything that currently connect to ur "changed computer" is not working try using this query in SSMS -– Get the current name of the SQL Server instance for later comparison. SELECT @@servername –- Remove server from the list of known remote and linked servers on the local instance of SQL Server. EXEC master.dbo.sp_dropserver ‘[SERVER NAME]‘ –- Define the name of the local instance of SQL Server. EXEC master.dbo.sp_addserver ‘[NEW SERVER NAME]‘, ‘local’ –- Get the new name of the SQL Server instance for comparison. SELECT @@servername after try, u must restart sql server services...then check if the query is working now see u