13 April 2015

Script to create insert statements for each row in the specified table

 
/*
Use this script to create insert statements for each row in the specified table.
Instructions:
1. Set the database you want to script from as normal.
2. change the set @TableName = '' line to be the
table you want to script out.
3. Run the script and copy all the text from the results below
the line with all the dashes (----).
Notes:
   If you get the error message "Invalid object name ''."
   then you either forgot to set the correct database or you spelled
   your table name wrong
Credits:
  Bob Wiechman - Fix for smalldatetime support
  Richard Lesh - correct support of uniqueidentifiers, automatic setting of Identity off/on, add Where clause support, more detail in debug mode.
  Sameer - Fix data integrity issues
*/
declare @TableName sysname
declare @WhereClause  varchar(1024)
declare @IdentityInsert int
declare @ColName sysname
declare @ColType tinyint
declare @ColStatus tinyint
declare @DebugMode bit
declare @ColList nvarchar(4000)
declare @ValList nvarchar(4000)
declare @SQL1 nvarchar(1000)
declare @SQL2 nchar(10)
declare @SQL3 nchar(1000)
set @TableName = 'version'  --  ''
set @WhereClause = ''    -- limit scope of inserts
set @DebugMode = 0    -- set to 1 if you only want a script
set @IdentityInsert = 0                -- set to 1 if you want to force IDENTITY_INSERT statements
set @ColList = ''
set @ValList = ''
set @SQL1 = 'select replace(''insert into ' + @TableName + ' ('
set @SQL2 = ') values ('
set @SQL3 = ')'', ''''''null'''''', ''null'') from ' + @TableName
if @DebugMode = 1 print '-- StmtShell: ' + @sql1 + @sql2 + @sql3
declare csrColumns cursor local fast_forward for
  select c.name, c.xtype, c.status
  from syscolumns c
    inner join sysobjects o
      on o.id = c.id
  where o.name = @TableName
    and o.xtype in ('U', 'S')
  order by ColID
open csrColumns
fetch next from csrColumns into @ColName, @ColType, @ColStatus
while @@fetch_status = 0
begin
  set @ColList = @ColList + ' ' + @ColName
  if @ColType in (173, 104, 106, 62, 56, 60, 108, 59, 52, 122, 48, 165)    -- numeric types (nulls not supported yet)
    set @ValList = @ValList + ' ''+convert(varchar(200),' + @ColName + ')+'''
  else if @ColType in (175, 239, 231, 231, 167)                            -- uid and string types
    set @ValList = @ValList + ' ''''''+isnull(' + @ColName + ',''null'')+'''''''
  else if @ColType in (58, 61)                                             -- dates (nulls not supported yet)
    set @ValList = @ValList + ' ''''''+convert(varchar(200),' + @ColName + ')+'''''''
  else if @ColType = 36                                                    -- uniqueidentfiers (nulls not supported yet)
    set @ValList = @ValList + ' ''''{''+convert(varchar(200),' + @ColName + ')+''}'''''
  if @DebugMode = 1             begin print '-- @ValList: ' + rtrim(@ValList) end
  if (@ColStatus & 0x80) = 0x80 begin set @IdentityInsert = 1 end          -- Check if column has Identity attribute
  fetch next from csrColumns into @ColName, @ColType, @ColStatus
end
close csrColumns
deallocate csrColumns
set @ColList = replace(ltrim(@ColList), ' ', ', ')
set @ValList = replace(ltrim(@ValList), ' ', ', ')
if @IdentityInsert = 1
  print 'set identity_insert ' + @TableName + ' on'
if @DebugMode = 1
  print @SQL1 + @ColList + @SQL2 + @ValList + @SQL3 + ' ' + @WhereClause
else
  exec (@SQL1 + @ColList + @SQL2 + @ValList + @SQL3 + ' ' + @WhereClause)
if @IdentityInsert = 1
  print 'set identity_insert ' + @TableName + ' off'

02 January 2015

Run ASP.NET Website with .NET Framework v1.1 on IIS 8 Windows Server 2012


1) Install IIS with IIS6 meta base compatibilities
2) Install Framework V1.1, SP1 and Security patches.
3) Enable V1.1 in IIS ISAPI and CGI Restrictions.
4) Deploy Site and See if it works. If it didn't work and gives 404 handlers errors goto next step.
5) In web.config add following 1.1 handler mappings just above this tags </configuration>







<system.webServer>
        <handlers>
            <add name="ASPNET-ISAPI-1.1-WebServiceHandlerFactory" path="*.asmx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.Net\Framework\v1.1.4322\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv1.1,bitness32" />
            <add name="ASPNET-ISAPI-1.1-SimpleHandlerFactory" path="*.ashx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.Net\Framework\v1.1.4322\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv1.1,bitness32" />
            <add name="ASPNET-ISAPI-1.1-HttpRemotingHandlerFactory-soap" path="*.soap" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.Net\Framework\v1.1.4322\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv1.1,bitness32" />
            <add name="ASPNET-ISAPI-1.1-PageHandlerFactory" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.Net\Framework\v1.1.4322\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv1.1,bitness32" />
            <add name="ASPNET-ISAPI-1.1-HttpRemotingHandlerFactory-rem" path="*.rem" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.Net\Framework\v1.1.4322\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv1.1,bitness32" />
            <remove name="ASPNET-ISAPI-1.1-AXD" />
            <add name="ASPNET-ISAPI-1.1-AXD" path="*.axd" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v1.1.4322\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv1.1,bitness32" />
        </handlers>
</system.webServer>


Enjoy the running site :)
Note: Make sure to backup your current configs.

Thank you,






26 November 2014

Factors Influencing Consumers Purchase Intentions towards Private Brands

Abstract

The change in market trends, of late, is marked by the growth of ‘brands’ for consumable items. Now, people prefer ‘branded’ products even for household use instead of random selection. Keeping in view the changing trend, this study explores the factors influencing purchase of private brands in Karachi and to understand how those factors affect the purchase intentions of consumers towards private brands.

12 January 2012

How to check if a file exists on remote/local server using php

Linking to a file or displaying an image from remote server is very common practice these days. But problem occurs when the file is not there on the remote server and our page starts showing a broken link. For this problem I have few solutions that will help you in avoiding this issue.

Solution # 1: Using file_exists()

Syntax
file_exists(string $filename)

02 June 2011

Creating a connection to MySQL in PHP - Php For Beginners - Lesson 11

Whenever we want to access the data in the mysql database using php, we have to create a connection to that particular database. Once the connection is establish we can insert and retrieve any data from the mysql database.

Creating a Mysql connection is quite simple in php, a simple built-in php function "mysql_connect()" is used for this purpose.

Syntax:
mysql_connect(servername,username,password); 
Where servername is the name of the server to connect, username and password are the credentials used to connect to the database.

Selecting a Database:
Once a connection is established to the database, we have to select the particular database that we want to use for inserting and fetching the data. This can be done by using another built-in php function "mysql_select_db()".
Syntax:
mysql_select_db(database,connection)
Where database is the name of the database and connection is the connection created in the earlier part of this article.

Working Example:
Since connecting and selecting the database is required each time we want to use a database. So we can save the code for creating the connection and selecting the database in a file and include it wherever we want to use the database. You can name that file as "connection.php" or whatever other name you want. Contents of this file are as follows:
<?php
$db_host="localhost";
$db_user="root";
$db_pass="";
$db_name="any_db";

$con=mysql_connect($db_host,$db_user,$db_pass) or die ('Can not connect to database');
mysql_select_db($db_name,$con) or die ('Can not Select Database');
?>
If you are using this code on the local server then the above mentioned configuration will work fine, as the default host/server name is always "localhost", user name is always "root" and password is always "" for the local server, but if you are using it on some web server then you have to change these settings to your web server's settings. The db_name is the name of the database that you want to select.

Well I guess this is all for this lesson, for any queries, should you have, feel free to comment and ask.

next Previous Lesson