Skip to main content

Posts

Showing posts from 2012

Find size of SQL Server tables and other objects with stored procedure

my colleague needs a query to seek for all tables in certain Database then use it to display informati on such as: Created Date, Rows in that tables, etc at first i look over sp_spaceused but it end up wrapping query which is hard because undocumented and it failed :( also considerations can be used for SQL 2000 so i google it and found this link , it works for SQL 2000 and above i tweak a bit to meet my requirement but credit goes to  Richard Ding here is the query that i used USE master; GO IF OBJECT_ID(N'dbo.sp_SOS', N'P') IS NOT NULL   DROP PROCEDURE dbo.sp_SOS; GO CREATE PROCEDURE dbo.sp_SOS   @DbName sysname = NULL,   @SchemaName sysname = NULL,   @ObjectName sysname = N'%',   @TopClause nvarchar(20) = NULL,   @ObjectType nvarchar(50) = NULL,   @ShowInternalTable nvarchar(3) = NULL,   @OrderBy nvarchar(100) = NULL,   @UpdateUsage bit = 0 AS /*=============================================================...

Print Escape Character for printer Barcode in .NET

fiuhh, this case is one of the most annoying 'simple' approach requirement is to send 'barcode' to printer directly, because often we using Image print (creating image on the fly then send it to barcode printer)..this one althought works but often the image become blur / discarded so we need to 'communicate' to barcode printer using its 'language' the 'language' depends on the printer itself..in my case, we using SATO barcode printer so the 'language' is SBPL  (visit the link for more info) first we need to design the label we can use SBPL and design it 'on the fly' make us a little bit crazy or we can use SATO LABEL Gallery Free to do the job and generate SBPL equivalent for us so we can use it in our code after we design it, we use "Print to file" method for the printer then print it so we can see what its send to the printer the generated SBPL will contain 'unseen' character in visual studio ID...

Reset Identity Column Value in SQL Server

if u have identity column and of course before deployed it to production, u'll need to test the value when u done, u probably want to reset it to initial value (0 for example) so u have 'fresh' data for production u'll be need to use this syntax DBCC CHECKIDENT (orders, RESEED, 0) PS: the next value will be always +1, so in my case next value will be 1 until then

Date and Time format in SQL

this are some DATE and TIME format to use in SQL that i found when i'm googling a little YY-MM-DD SELECT SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 120), 3, 8) AS [YY-MM-DD] SELECT REPLACE(CONVERT(VARCHAR(8), GETDATE(), 11), '/', '-') AS [YY-MM-DD] 99-01-24 YYYY-MM-DD SELECT CONVERT(VARCHAR(10), GETDATE(), 120) AS [YYYY-MM-DD] SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 111), '/', '-') AS [YYYY-MM-DD] 1999-01-24 MM/YY SELECT RIGHT(CONVERT(VARCHAR(8), GETDATE(), 3), 5) AS [MM/YY] SELECT SUBSTRING(CONVERT(VARCHAR(8), GETDATE(), 3), 4, 5) AS [MM/YY] 08/99 MM/YYYY SELECT RIGHT(CONVERT(VARCHAR(10), GETDATE(), 103), 7) AS [MM/YYYY] 12/2005 YY/MM SELECT CONVERT(VARCHAR(5), GETDATE(), 11) AS [YY/MM] 99/08 YYYY/MM SELECT CONVERT(VARCHAR(7), GETDATE(), 111) AS [YYYY/MM] 2005/12 Month DD, YYYY  1 SELECT DATENAME(MM, GETDATE()) + RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9) AS [Month DD, YYYY] July 04, 2006 1 Mon YYYY 1 SELECT SUBSTRING(CONV...

Search specific string inside Stored Procedure, View, Function, Trigger, Table Name, Table Field in SQL Server

this query can be used to search specific string inside, no need to right click  - modify - and search manually from Query designer / SSMS DECLARE @NextString NVARCHAR(40) DECLARE @Pos INT DECLARE @NextPos INT DECLARE @String NVARCHAR(40) DECLARE @Delimiter NVARCHAR(40) DECLARE @Query nvarchar(2000) DECLARE @WHERE nvarchar(1000) DECLARE @Query2 nvarchar(2000) DECLARE @Where2 nvarchar(1000) SET @Query =  'SELECT DISTINCT so.name, ' +    'CASE so.xtype ' +     'WHEN ''P'' THEN ''SPROC'' ' +     'WHEN ''IF'' THEN ''FUNCTION'' ' +     'WHEN ''FN'' THEN ''FUNCTION'' ' +     'WHEN ''V'' THEN ''VIEW'' ' +     'WHEN ''U'' THEN ''TABLE'' ' +     'WHEN ''TR'' THEN ''TRIGGER'' ' +    'END AS [TYPE] ' +  'FROM...

Cannot obtain the schema rowset "DBSCHEMA_TABLES_INFO" for OLE DB provider "SQLNCLI" for linked server [linked_server_name]

just got this error when try to execute query against LinkServer (SQL 2000) from SQL 2005 eventhough the link can create but i can't do 4 parts query select * from LINKED.DB.DBO.TABLE the problem because SQL 2000 needs to run certain SP that not exists in master so the LINK query can run create   procedure  sp_tables_info_rowset_64       @table_name  sysname ,       @table_schema      sysname   =   null,           @table_type  nvarchar ( 255 )   =   null as declare @Result int set @Result = 0 exec  @Result =  sp_tables_info_rowset  @table_name , @table_schema ,  @table_type this  solution  originally POST  by  Marek Adamczuk until then

Enable Samesite for the .NET Framework 3.5 SP1 bootstrapper package

hi, i recently got an error when trying to publish ClickOnce app that run under 3.5 framework. the error said " The install location for prerequisites has not been set to 'component vendor's web site' and the file 'dotNetFx35setup.exe' in item 'Microsoft.Net.Framework.3.5.SP1' cannot be located on disk." so i found the solution for this one Update the Package Data Open the [Program Files]\Microsoft SDKs\Windows\v6.0A\ Bootstrapper \Packages\DotNetFx35SP1 folder or % ProgramFiles (x86)%\Microsoft SDKs\Windows\v6.0A\ Bootstrapper \Packages\DotNetFx35SP1 on x64 operating systems Edit the Product.xml file in Notepad. Paste the following into the <  PackageFiles  > element:  < PackageFile  Name="TOOLS\clwireg.exe"/> < PackageFile  Name="TOOLS\clwireg_x64.exe"/> < PackageFile  Name="TOOLS\clwireg_ia64.exe"/> Find the element for <  PackageFile  Name="dotNetFX30\XPSEP...

Entity Framework 4 and SQL Server 2000

it can be done!!.. (Microsoft .NET,Microsoft SQL Server,Database) by Jason Skowronek on 11/07/2011 If you are unfortunate enough to have to support applications running on legacy SQL Server 2000 databases like me, you are probably aware of the limitation of Visual Studio 2010 and Entity Framework 4.0 for SQL Server 2000 . There are plenty of articles out there on work-arounds. I find this one the most direct and feasible. Granted, I have not looked into possible version issue that may result in doing it this way, but for the various applications on which I have worked, it is sufficiently elegant and functional. This a work-around. Let me repeat, this is a work-around! . Here are the steps to add a new Entity Framework 4 entity context to a Visual Studio 2010 project: Download the base entity data model for SQL Server 2000 file and save it to the project folder to which you wish to add the SQL 2000 entity context. Do NOT add it to your pr...

Failed to access IIS metabase

it happens to me when try do access published asp.net 2.0 using IIS.. i've tried reinstall .net framework (2.0), republish then failed again the solution that works for me are Copy the asp.net webpage folder then mapped it to IIS instead of use the Published page hope it works for others too see u

No application is associated with the specified file for this operation in c#

hi all, if u found exception like the Title "No application is associated with the specified file for this operation" when u try to use Process to execute something that u must try this: set the default program to open the file ex: file .txt extension then u must set the default program to Notepad then u can try it again to test if it worked this solution worked for me :D see u later