Gokul's Blog


Leave a comment

Sql Query to get the count of tables


Thanks to wim(commenter) from this blogpost: http://geekswithblogs.net/TakeNote/archive/2007/09/22/115537.aspx

SELECT '[' + SCHEMA_NAME(t.schema_id) + '].[' + t.name + ']' AS fulltable_name
, SCHEMA_NAME(t.schema_id) AS schema_name, 
t.name AS table_name, 
'select * from ' + t.name AS query, 
i.rows
FROM sys.tables AS t INNER JOIN
sys.sysindexes AS i ON t.object_id = i.id AND i.indid < 2

<strong>Tip-2: Slow</strong>
exec sp_MSforeachtable 'select count(*) as nr_of_rows, ''select * from ?'' as table_name from ?'


Leave a comment

Install WordPress multisite on Windows server 2003

Main Link

http://cottongraphicdesign.com/2011/08/how-to-install-wordpress-multisite-on-window-iis-6-in-7-steps/

Step 4 – Download and Install ISAPI Rewrite

The biggest challenge with getting IIS 6 to work with WordPress is that Windows does not have a native ISAPI rewrite filter in the web server. You have to download and install one. There are many choices, but Ionic’s ISAPI Rewrite Filter is free and it works, so why make it complicated, use this…

Click here to download Ionic’s ISAPI Rewrite Filter. Download the installer and run it on your web server.

Step 6 – Activate Multisite in WordPress

WordPress Multisite gives you 3 choices of how to differentiate your multiple websites: subdomain, subdirectory, or domain mapping. For simplicity, I chose to go with the subdirectory option because it uses the ISAPI rewrite filter that we have already installed, and it requires no further installations.

NOTE: If you have to go with the subdirectory option, it involves wildcard directories, and you can click here to read about how to set up wildcard subdomains for WordPress. If you have to go with the domain mapping option, you can click here to read about how to set up domain mapping in WordPress.

So as I said, I went with subdirectory differentiation for ease of installation, and it seemed to be more compatible with IIS since it required fewer installations. In fact, we are done with all the required installations, and we will now only need to modify some code to finish up.

Add this line to your wp-config.php file and save the file:

define(‘WP_ALLOW_MULTISITE’, true);

On the left column in the dashboard, you will see a new link called “Network” under “Tools.”  Disable all of your plugins, and then click the “Network” link. Select “Sub-directories” for the Network type, give the network a title, and enter the admin e-mail address.

NOTE: If you see this error it’s because you installed WordPress more than 30 days ago: “Because your install is not new, the sites in your WordPress network must use sub-domains. The main site in a sub-directory install will need to use a modified permalink structure, potentially breaking existing links.” The work around solution is simply to ignore this message and change the line in the wp-config.php file that says “define( ‘SUBDOMAIN_INSTALL’, true );” to “define( ‘SUBDOMAIN_INSTALL’, false );” but be sure you backup your database before you try to go this route. If you are very worried about it, and you have a lot of posts, then you should consider using subdomains or domain mapping instead of subdirectories.

After you select the network type, title, and email, WordPress will display the code that is required for the wp-config.php and for the ISAPI rewrite filter. Copy the code that WordPress provides into the wp-config.php file as the WordPress directions explain. WordPress assumes the third chunk of code will be put into a file called “.htaccess” which would be correct if we were using Linux. Since we are using IIS 6 with the ISAPI filter we installed in step 4, we save the code that WordPress supplies for “.htaccess” but we save it in a file called “iirf.ini” and place that on the root of your WordPress web server.

 


Leave a comment

File Helpers to handle large text file

File Helpers to handle large text file

Sample Type
<pre>[Delimitedrecord("|")]
 public class SampleType
 {
	public string Field1;
	public int    Field2;
 }

For small files

FileHelperEngine&lt;SampleType&gt; engine = new FileHelperEngine&lt;SampleType&gt;();
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
_dataSet = engine.ReadFile(sourceFilePath).ToDataSet();

For large files
                    FileHelperAsyncEngine engine2 = new FileHelperAsyncEngine(typeof(SampleType));
                    engine2.BeginReadFile(sourceFilePath);

                    List&lt;SampleType&gt; records = new List&lt;SampleType&gt;();
                    int iCount = 0;
                    while (engine2.ReadNext() != null)
                    {
                        records.Add((SampleType)engine2.LastRecord);
                        if (iCount++ &gt; 10000)
                        {
                            //Put in a queue here and call the method to create dataset as follows
                            ///records.ToDataSet();
                            records = new List&lt;SampleType&gt;(); //rinse and repeat till all records are processed.
                        }
                        // put your code here !!!!
                        Console.WriteLine("Data " + records[0].Field1 + " , " + records[0].Field2.ToString());

                    }
Extension method to create Dataset from a list.
 #region Extension Classes
    static class Extensions
    {
        public static DataSet ToDataSet&lt;T&gt;(this IList&lt;T&gt; list)
        {
            Type elementType = typeof(T);
            DataSet ds = new DataSet();
            DataTable t = new DataTable(elementType.Name);
            ds.Tables.Add(t);

            //add a column to table for each public property on T
            foreach (var propInfo in elementType.GetProperties())
            {
                Type ColType = Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType;

                t.Columns.Add(propInfo.Name, ColType);
            }

            //go through each property on T and add each value to the table
            foreach (T item in list)
            {
                DataRow row = t.NewRow();

                foreach (var propInfo in elementType.GetProperties())
                {
                    row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value;
                }

                t.Rows.Add(row);
            }

            return ds;
        }
    }
    #endregion


Leave a comment

BizTalk Mapping from .Net Code

I came across a few articles sometime back on how to access BizTalk maps or use the XSLT generated from the maps in .net Code.

Here are a few links: