<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>I do MS SQL Server</title>
	<atom:link href="http://idosql.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://idosql.com</link>
	<description>Integration Services - Analysis Services - Reporting Services [2005, 2008, 2012]</description>
	<lastBuildDate>Tue, 01 May 2012 17:34:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Analysis Services 2008 Workshop</title>
		<link>http://idosql.com/2012/04/21/analysis-services-2008-workshop/</link>
		<comments>http://idosql.com/2012/04/21/analysis-services-2008-workshop/#comments</comments>
		<pubDate>Sat, 21 Apr 2012 08:00:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Professional Development]]></category>

		<guid isPermaLink="false">http://idosql.com/?p=325</guid>
		<description><![CDATA[Written by: Luis Miguel &#8211; Originally published on: April 21, 2012 The folks from Pragmatic Works were back in So. Fla. about three weeks ago, this time with a workshop based in Analysis Services 2008, after the positive experience with their previous session, I could not miss this one. To sum it up, again, I [...]]]></description>
			<content:encoded><![CDATA[<p>Written by: Luis Miguel &#8211; Originally published on: April 21, 2012</p>
<p>The folks from Pragmatic Works were back in So. Fla. about three weeks ago, this time with a workshop based in Analysis Services 2008, after the positive experience with their previous session, I could not miss this one.</p>
<p>To sum it up, again, I was not disappointed. This was a two-day class and the instructor was Devin (Brian’s brother).</p>
<p>The good thing about these workshops is that even though they use Microsoft’s sample database AdventureWorks, Pragmatic Works always sprinkle you with real-world examples as realistic as possible if only to put the matter at hand in perspective of how it applies to scenarios we come across at work.</p>
<p>For an introductory class it was well worth the time and money spent, no regrets <img src='http://idosql.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . I wish they had shown an example of building cubes from the ground up, starting with the definition of the Dimensions, instead of using the wizard but I guess that could be considered advanced stuff. They did go into Data Mining with an excellent explanation of basic concepts, which at this level was a nice bonus.</p>
<p>Plus, another shirt, another book, for what I heard from other participants in the workshop, the anticipation from the audience now is for an SSRS class.</p>
]]></content:encoded>
			<wfw:commentRss>http://idosql.com/2012/04/21/analysis-services-2008-workshop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Exporting a dataset to a Flat File Destination in SSIS 2008 [DRAFT]</title>
		<link>http://idosql.com/2012/02/06/exporting-a-dataset-to-a-flat-file-destination-in-ssis-2008/</link>
		<comments>http://idosql.com/2012/02/06/exporting-a-dataset-to-a-flat-file-destination-in-ssis-2008/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 00:43:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://idosql.com/?p=289</guid>
		<description><![CDATA[Written by Luis Miguel &#8211; Originally Published on Feb. 6, 2012 Here is a fairly detailed description of the request coming from management: 1 &#8211; Gather a list of new records from the Customers table and save it to a flat file on a local disk nightly 2 &#8211; Generate a fixed width ASCI file [...]]]></description>
			<content:encoded><![CDATA[<p>Written by Luis Miguel &#8211; Originally Published on Feb. 6, 2012</p>
<p>Here is a fairly detailed description of the request coming from management:</p>
<p>1 &#8211; Gather a list of new records from the Customers table and save it to a flat file on a local disk nightly<br />
2 &#8211; Generate a fixed width ASCI file with the following structure:<br />
Attribute (Field length)<br />
- Customer Number (16)<br />
- Customer Name (128)<br />
- Address1 (128)<br />
- Address2 (128)<br />
- City (64)<br />
- State (2)<br />
- Zip (10)<br />
- Company Id (16)</p>
<p>3 &#8211; Fill shorter values with spaces so all columns stay aligned in the flat file<br />
4 &#8211; Segregate the datasets by accounting company and put them in separate text files<br />
5 &#8211; Generate a file name with the following scheme companyname_yyyymmdd.txt</p>
<p>The following is a step-by-step guide of the process implemented using Integration Services 2008 to fulfill the requirements</p>
<p>I &#8211; Create a table with CHAR data type columns</p>
<p>There are two tables involved in this process<br />
a &#8211; CUSTOMER_EXPORT &#8211; Is the list of companies to process since management does not want to include all companies in this process, the stored procedure reads from this table and performs the extract/save for the records marked export_ = 1 (True)</p>
<div id="attachment_300" class="wp-caption aligncenter" style="width: 258px"><a href="http://idosql.com/wp-content/uploads/2012/02/customer_export_table1.jpg"><img class="size-medium wp-image-300" title="customer_export_table" src="http://idosql.com/wp-content/uploads/2012/02/customer_export_table1-248x300.jpg" alt="" width="248" height="300" /></a><p class="wp-caption-text">The Customer Export table where accounting company databases are flagged for processing</p></div>
<p>b &#8211; CUSTOMERS is the complete list of customers from all the companies, every single column on every single row in this table needs to have a value (a space for empty fields, empty fields cannot be NULL) so that in the query the empty fields become a string of spaces</p>
<p>The structure of the Customer table<br />
<div id="attachment_306" class="wp-caption aligncenter" style="width: 238px"><a href="http://idosql.com/wp-content/uploads/2012/02/customer_table_design.jpg"><img src="http://idosql.com/wp-content/uploads/2012/02/customer_table_design-228x300.jpg" alt="" title="customer_table_design" width="228" height="300" class="size-medium wp-image-306" /></a><p class="wp-caption-text">The Customer table in design view, all relevant fields are CHAR type and do not allow nulls</p></div></p>
<p>The Customer table data<br />
<div id="attachment_308" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2012/02/customer_table_data.jpg"><img src="http://idosql.com/wp-content/uploads/2012/02/customer_table_data-300x265.jpg" alt="" title="customer_table_data" width="300" height="265" class="size-medium wp-image-308" /></a><p class="wp-caption-text">The Customer table data, the field 'updated_on' is used to identify (new) records to be exported</p></div></p>
<p>2 &#8211; Build a package to extract the data and save it to disk<br />
3 &#8211; Write a stored procedure to drive the SSIS package<br />
4 &#8211; Add an SQL Server job that executes the stored procedure every night</p>
<p>Create a new SSIS package and set its security to &#8220;Encrypt Sensitive with password&#8221;</p>
<p>2 &#8211; Create 3 package variables and set their data type to STRING<br />
a &#8211; flat_file, company_id, export_date<br />
<div id="attachment_314" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2012/02/package_variables.jpg"><img src="http://idosql.com/wp-content/uploads/2012/02/package_variables-300x289.jpg" alt="" title="package_variables" width="300" height="289" class="size-medium wp-image-314" /></a><p class="wp-caption-text">The three package variables that will be passed as arguments when executing the package from the stored procedure</p></div><br />
3 &#8211; Connection Managers<br />
a &#8211; Add an OLE DB connection to the source database, use SQL Server authentication, in the real world your Windows credentials will not be calling the package and reading the data from the database<br />
<div id="attachment_316" class="wp-caption aligncenter" style="width: 296px"><a href="http://idosql.com/wp-content/uploads/2012/02/ole_db_connection.jpg"><img src="http://idosql.com/wp-content/uploads/2012/02/ole_db_connection-286x300.jpg" alt="" title="ole_db_connection" width="286" height="300" class="size-medium wp-image-316" /></a><p class="wp-caption-text">The OLE DB connection using SQL Server authentication and the option to save the password, passwords are encrypted everywhere they are used.</p></div><br />
b &#8211; Add a flat file connection to the target text file, use an expression so that the destination file name can be dynamically generated, in this case the expression is &#8220;ConnectionString = @[User::flat_file]<br />
<div id="attachment_320" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2012/02/flat_file_connection1.jpg"><img src="http://idosql.com/wp-content/uploads/2012/02/flat_file_connection1-300x240.jpg" alt="" title="flat_file_connection" width="300" height="240" class="size-medium wp-image-320" /></a><p class="wp-caption-text">The flat file connection using an expression for the connection string so the destination file name can be generated dynamically</p></div><br />
4 &#8211; Add a Data Flow Task<br />
a &#8211; Add an OLE DB source to the Customer table and use the SQL Command</p>
<pre>
SELECT
[customer_number] +
[name] +
[address1] +
[address2] +
[city] +
[state] +
[zip] +
[company_id] AS customer_record
FROM customers WHERE company_id = ? AND updated_on = ?
</pre>
<p>b &#8211; Set the input parameters to the variables company_id and export_date</p>
<p>[insert picture here]</p>
<p>c &#8211; Add a Flat File Destination and connect the output of the OLE DB data source to it</p>
<p>[insert picture here]</p>
<p>5 &#8211; Create a stored procedure to call (execute) or &#8220;run&#8221; the package<br />
a &#8211; Make sure you encrypt the store procedure so that the package password is not visible<br />
b &#8211; Keep the package password in a safe place, you will need it to open the package in BIDS</p>
<p>CREATE  PROCEDURE [dbo].[usp_client_file]<br />
WITH ENCRYPTION<br />
AS<br />
DECLARE @year_ CHAR(4)<br />
DECLARE @month_ CHAR(2)<br />
DECLARE @day_ CHAR(2)<br />
DECLARE @export_date VARCHAR(128)<br />
DECLARE @insert_command VARCHAR(2048)<br />
DECLARE @company VARCHAR(128)<br />
DECLARE @company_id VARCHAR(16)<br />
DECLARE @flat_file VARCHAR(128)<br />
DECLARE @dtexec_ VARCHAR(2048)<br />
SET @year_ = CAST(DATEPART(year, getdate()) AS CHAR(4))<br />
IF DATEPART(MONTH, GETDATE()) &lt; 10 SET @month_ = &#8217;0&#8242; + CAST(DATEPART(MONTH, GETDATE()) AS CHAR(2)) ELSE SET @month_ = CAST(DATEPART(MONTH, GETDATE()) AS CHAR(2))<br />
IF DATEPART(DAY, GETDATE()) &lt; 10 SET @day_ = &#8217;0&#8242; + CAST(DATEPART(DAY, GETDATE()) AS CHAR(2)) ELSE SET @day_ = CAST(DATEPART(DAY, GETDATE()) AS CHAR(2))<br />
SET @export_date = @year_ + @month_ + @day_<br />
DECLARE db_cursor CURSOR FOR<br />
SELECT name FROM [dbo].[customer_export] WHERE export_ = 1<br />
OPEN db_cursor<br />
FETCH NEXT FROM db_cursor INTO @company<br />
WHILE @@FETCH_STATUS = 0<br />
BEGIN<br />
SET @company_id = (SELECT company_id FROM customer_export WHERE name = @company)<br />
SET @dtexec_ = &#8216;dtexec /FILE c:\ssis\packages\clients_file.dtsx /DE &#8220;y0ur_p@ssw0rd&#8221; /SET \Package.Variables[User::flat_file].Value;&#8221;\&#8221;c:\exports\&#8217; + @company + &#8216;_&#8217; + @export_date + &#8216;.txt&#8221;" /SET \Package.Variables[User::export_date].Value;&#8217; + @export_date + &#8216; /SET \Package.Variables[User::company_id].Value;&#8217; + @company_id + &#8221;<br />
EXEC xp_cmdshell @dtexec_<br />
FETCH NEXT FROM db_cursor INTO @company<br />
END<br />
CLOSE db_cursor<br />
DEALLOCATE db_cursor</p>
<p>And that takes care of the assignment, if you schedule this stored procedure to run once a day, the package will extract a list of new customers and save it to local storage using a unique file name driven by a timestamp</p>
]]></content:encoded>
			<wfw:commentRss>http://idosql.com/2012/02/06/exporting-a-dataset-to-a-flat-file-destination-in-ssis-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the SSIS 2008 Foreach Loop Container</title>
		<link>http://idosql.com/2011/11/27/using-the-ssis-2008-foreach-loop-container/</link>
		<comments>http://idosql.com/2011/11/27/using-the-ssis-2008-foreach-loop-container/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 15:04:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://idosql.com/?p=257</guid>
		<description><![CDATA[Written by Luis Miguel – Originally published on November 27, 2011 This post is a demonstration of how to use the SSIS 2008 Foreach Loop Container to execute a routine against a dataset one record at a time. I have chosen the DBA task of fixing orphaned users to illustrate this technique. The challenge: We [...]]]></description>
			<content:encoded><![CDATA[<p>Written by Luis Miguel – Originally published on November 27, 2011</p>
<p>This post is a demonstration of how to use the SSIS 2008 Foreach Loop Container to execute a routine against a dataset one record at a time. I have chosen the DBA task of fixing orphaned users to illustrate this technique.</p>
<p>The challenge: We need to restore several databases that are ready for testing from our Development environment into our UAT instance, as this databases are restored the login/user &#8220;links&#8221; are lost and we end up with orphaned users, if we restore a dozen databases and our testing group consist of another dozen users the task of manually fixing them becomes a little daunting.</p>
<p>The solution: Use an SSIS package to automate the process of executing the system stored procedure SP_CHANGE_USERS_LOGIN to each an every user on each and every database</p>
<p>Fig. 1 &#8211; A list of &#8220;fake&#8221; databases and users in my Lab&#8217;s UAT system, the target of the multiple database restores<br />
<div id="attachment_260" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach2.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach2-300x253.jpg" alt="List of databases and logins" title="List of databases and logins" width="300" height="253" class="size-medium wp-image-260" /></a><p class="wp-caption-text">List of databases and logins</p></div></p>
<p>Fig. 2 &#8211; The user ABROWN exists &#8220;Without Login&#8221; after the restore<br />
<div id="attachment_263" class="wp-caption aligncenter" style="width: 278px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach4.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach4-268x300.jpg" alt="Database user without login" title="Database user without login" width="268" height="300" class="size-medium wp-image-263" /></a><p class="wp-caption-text">Database user without login</p></div></p>
<p>Fig. 3 &#8211; A high level view of the package using the Foreach Loop Container<br />
<div id="attachment_265" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach5.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach5-300x217.jpg" alt="High level view of the package with the Foreach Loop Container" title="High level view of the package with the Foreach Loop Container" width="300" height="217" class="size-medium wp-image-265" /></a><p class="wp-caption-text">High level view of the package with the Foreach Loop Container</p></div></p>
<p>1 &#8211; Add an OLE DB connection to the package<br />
<div id="attachment_267" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach15.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach15-300x284.jpg" alt="The OLE DB connection" title="The OLE DB connection" width="300" height="284" class="size-medium wp-image-267" /></a><p class="wp-caption-text">The OLE DB connection</p></div></p>
<p>2 &#8211; Add a package level variable and set its type Object, for this example I called this variable &#8220;db_login_ado&#8221;</p>
<p>3 &#8211; Add an Execute SQL Task (code below) and set the ResultSet property to &#8220;Full result set&#8221;<br />
SELECT D.name AS database_, L.name AS login_<br />
FROM sys.databases D, sys.server_principals L<br />
WHERE D.database_id > 4 AND (L.type_desc = &#8216;sql_login&#8217;)<br />
ORDER BY D.name<br />
<div id="attachment_269" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach6.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach6-300x251.jpg" alt="Execute SQL Task" title="Execute SQL Task" width="300" height="251" class="size-medium wp-image-269" /></a><p class="wp-caption-text">Execute SQL Task</p></div></p>
<p>3a &#8211; Add a result set, call it 0 (zero) and assign it to the db_login_ado variable<br />
<div id="attachment_271" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach7.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach7-300x251.jpg" alt="Result set 0 of the Execute SQL Task" title="Result set 0 of the Execute SQL Task" width="300" height="251" class="size-medium wp-image-271" /></a><p class="wp-caption-text">Result set 0 of the Execute SQL Task</p></div></p>
<p>4 &#8211; Add a Foreach Loop Container and set it&#8217;s collection to &#8220;foreach ado enumerator&#8221;</p>
<p>4a &#8211; In the Collection area of the this container set the &#8220;ADO object source variable&#8221; property to the variable coming from the Execute SQL Task<br />
<div id="attachment_273" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach9.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach9-300x286.jpg" alt="The Foreach Loop Container" title="The Foreach Loop Container" width="300" height="286" class="size-medium wp-image-273" /></a><p class="wp-caption-text">The Foreach Loop Container</p></div></p>
<p>5 &#8211; Add two String variables, one for the databases and the other one for the logins</p>
<p>6 &#8211; In the Variable Mappings area of the container add two entries one for each one of the string variables you just added in the previous step. Make sure your &#8220;database&#8221; variable, which the first column of the dataset is set to Index 0 and the &#8220;logins&#8221; variable, which the second column in the dataset is set to index 1<br />
<div id="attachment_275" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach10.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach10-300x286.jpg" alt="Variable Mappins of the Foreach Loop Container" title="Variable Mappins of the Foreach Loop Container" width="300" height="286" class="size-medium wp-image-275" /></a><p class="wp-caption-text">Variable Mappins of the Foreach Loop Container</p></div></p>
<p>7 &#8211; Add an execute sql task to the foreach container<br />
DECLARE @dbname VARCHAR(128)<br />
DECLARE @dbuser VARCHAR(128)<br />
DECLARE @commandchangeuser VARCHAR(1024)<br />
SET @dbname = ?<br />
SET @dbuser = ?<br />
SET @commandchangeuser = &#8216;USE &#8216; + @dbname + &#8216;; IF EXISTS (SELECT name FROM sysusers WHERE name = &#8221;&#8217; + @dbuser + &#8221;&#8217;)  EXEC sp_change_users_login &#8221;auto_fix&#8221;, &#8216; + @dbuser + &#8221;<br />
EXECUTE(@commandchangeuser)<br />
<div id="attachment_279" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach11.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach11-300x244.jpg" alt="Execute SQL Task inside the Foreach Loop Container" title="Execute SQL Task inside the Foreach Loop Container" width="300" height="244" class="size-medium wp-image-279" /></a><p class="wp-caption-text">Execute SQL Task inside the Foreach Loop Container</p></div></p>
<p>7a &#8211; Map the input parameters to the string variables set in the Foreach Loop Container, parameter names must be 0 and 1, the parameter size is the length of the VARCHAR data type<br />
<div id="attachment_280" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach12.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach12-300x244.jpg" alt="Parameter Mappings of the Execute SQL Task" title="Parameter Mappings of the Execute SQL Task" width="300" height="244" class="size-medium wp-image-280" /></a><p class="wp-caption-text">Parameter Mappings of the Execute SQL Task</p></div></p>
<p>A successful run of the package<div id="attachment_282" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach13.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach13-300x295.jpg" alt="The execution of the pacakage completed successfuly" title="The execution of the pacakage completed successfuly" width="300" height="295" class="size-medium wp-image-282" /></a><p class="wp-caption-text">The execution of the pacakage completed successfuly</p></div></p>
<p>The user ABROWN is now linked to the login ABROWN after running the package<br />
<div id="attachment_283" class="wp-caption aligncenter" style="width: 310px"><a href="http://idosql.com/wp-content/uploads/2011/11/foreach14.jpg"><img src="http://idosql.com/wp-content/uploads/2011/11/foreach14-300x281.jpg" alt="User status after the package ran" title="User status after the package ran" width="300" height="281" class="size-medium wp-image-283" /></a><p class="wp-caption-text">User status after the package ran</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://idosql.com/2011/11/27/using-the-ssis-2008-foreach-loop-container/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importing a server-side trace into a table and recycling the trace file</title>
		<link>http://idosql.com/2011/11/06/importing-a-server-side-trace-into-a-table-and-recycling-the-trace-file-draft/</link>
		<comments>http://idosql.com/2011/11/06/importing-a-server-side-trace-into-a-table-and-recycling-the-trace-file-draft/#comments</comments>
		<pubDate>Sun, 06 Nov 2011 13:39:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Monitoring]]></category>

		<guid isPermaLink="false">http://idosql.com/?p=242</guid>
		<description><![CDATA[Written by Luis Miguel – Originally published on November 6, 2011 Bringing the data captured by a server-side trace into a table is a very convenient way to review the trace results when monitoring and analyzing database activity. One thing I immediately thought of when implementing this kind of solution was to do it periodically [...]]]></description>
			<content:encoded><![CDATA[<p>Written by Luis Miguel – Originally published on November 6, 2011</p>
<p>Bringing the data captured by a server-side trace into a table is a very convenient way to review the trace results when monitoring and analyzing database activity. One thing I immediately thought of when implementing this kind of solution was to do it periodically and incrementally.</p>
<p>SQL Server 2008 does not come with built-in functionality to append data to an existing trace file or to overwrite it and start fresh using the same file name.</p>
<p>One possible arrangement to achieve this has been explained in other blogs and requires the use of several trace files which is SQL Server&#8217;s default behavior. Since this technique is not without flaws and I can afford to stop the data capturing process for a minute while I import the data and refresh the trace file I did come up with the following script which lets me simulate the &#8220;refreshing&#8221; feature not available in SQL Server 2008.</p>
<p>Run this command first to build the table that is going to store the trace data before you put the script in a store procedure or an SQL Server Agent job</p>
<p><font face="Courier New" size="2"><br />
<font color = "blue">SELECT</font>&nbsp;<font color = "silver">*</font><br />
<font color = "blue">INTO</font>&nbsp;&nbsp;&nbsp;<font color = "maroon">db_name</font><font color = "silver">.</font><font color = "maroon">schema_name</font><font color = "silver">.</font><font color = "maroon">table_name</font><br />
<font color = "blue">FROM</font>&nbsp;&nbsp;&nbsp;<font color = "fuchsia"><i>Fn_trace_gettable</i></font><font color = "maroon">(</font><font color = "red">&#8216;d:\trace\my_trace_file.trc&#8217;</font><font color = "silver">,</font>&nbsp;<font color = "blue">DEFAULT</font><font color = "maroon">)</font>&nbsp;<font color = "maroon">trace</font>&nbsp;<br />
</font></p>
<p>Once you have the table in place you can use the script below to keep adding data to it as frequently as necessary or possible</p>
<p><font face="Courier New" size="2"><br />
<font color = "blue">DECLARE</font>&nbsp;<font color = "#8000FF">@trace_id</font>&nbsp;<font color = "black"><i>INT</i></font><br />
<font color = "green"><i>&#45;&#45;&nbsp;Use&nbsp;the&nbsp;path&nbsp;to&nbsp;your&nbsp;trace&nbsp;file&nbsp;to&nbsp;get&nbsp;the&nbsp;Id&nbsp;of&nbsp;the&nbsp;trace&nbsp;you&nbsp;are&nbsp;working&nbsp;with</i></font><br />
<font color = "blue">SET</font>&nbsp;<font color = "#8000FF">@trace_id</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "maroon">(</font><font color = "blue">SELECT</font>&nbsp;<font color = "maroon">id</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">FROM</font>&nbsp;&nbsp;&nbsp;<font color = "maroon">sys</font><font color = "silver">.</font><font color = "maroon">traces</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">WHERE</font>&nbsp;&nbsp;<font color = "maroon">[path]</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "red">&#8216;d:\trace\my_trace_file.trc&#8217;</font><font color = "maroon">)</font><br />
<font color = "green"><i>&#45;&#45;&nbsp;If&nbsp;you&nbsp;get&nbsp;something&nbsp;back&nbsp;the&nbsp;trace&nbsp;is&nbsp;running</i></font><br />
<font color = "blue">IF</font>&nbsp;<font color = "#8000FF">@trace_id</font>&nbsp;<font color = "blue">IS</font>&nbsp;<font color = "blue">NOT</font>&nbsp;<font color = "blue">NULL</font><br />
&nbsp;&nbsp;<font color = "blue">BEGIN</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "green"><i>&#45;&#45;&nbsp;Stop&nbsp;the&nbsp;trace&nbsp;so&nbsp;it&nbsp;dumps&nbsp;the&nbsp;data&nbsp;into&nbsp;the&nbsp;file</i></font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">EXEC</font>&nbsp;<font color = "#FF0080"><b>Sp_trace_setstatus</b></font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "#8000FF">@traceid</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "#8000FF">@trace_id</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "#8000FF">@status</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "black">0</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "green"><i>&#45;&#45;&nbsp;Import&nbsp;the&nbsp;data&nbsp;from&nbsp;the&nbsp;trace&nbsp;file&nbsp;into&nbsp;a&nbsp;table</i></font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">INSERT</font>&nbsp;<font color = "blue">INTO</font>&nbsp;<font color = "maroon">db_name</font><font color = "silver">.</font><font color = "maroon">schema_name</font><font color = "silver">.</font><font color = "maroon">table_name</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">SELECT</font>&nbsp;<font color = "silver">*</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">FROM</font>&nbsp;&nbsp;&nbsp;<font color = "fuchsia"><i>Fn_trace_gettable</i></font><font color = "maroon">(</font><font color = "red">&#8216;d:\trace\my_trace_file.trc&#8217;</font><font color = "silver">,</font>&nbsp;<font color = "blue">DEFAULT</font><font color = "maroon">)</font>&nbsp;<font color = "maroon">trace</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">EXEC</font>&nbsp;<font color = "#FF0080"><b>Sp_trace_setstatus</b></font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "#8000FF">@traceid</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "#8000FF">@trace_id</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "#8000FF">@status</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "black">2</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "green"><i>&#45;&#45;&nbsp;Delete&nbsp;the&nbsp;trace&nbsp;file</i></font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">EXEC</font>&nbsp;<font color = "#FF0080"><b>Xp_cmdshell</b></font>&nbsp;<font color = "red">&#8216;erase&nbsp;d:\trace\my_trace_file.trc&#8217;</font><br />
&nbsp;&nbsp;<font color = "blue">END</font>&nbsp;<br />
</font></p>
<p>Now you are ready to kick start the trace again using the same (fixed) file name you used before, probably another step in an SQL Server Agent job.</p>
]]></content:encoded>
			<wfw:commentRss>http://idosql.com/2011/11/06/importing-a-server-side-trace-into-a-table-and-recycling-the-trace-file-draft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lifelong Learning &#8211; Knowledge is your friend</title>
		<link>http://idosql.com/2011/10/15/lifelong-learning-stay-abreast-to-stay-afloat/</link>
		<comments>http://idosql.com/2011/10/15/lifelong-learning-stay-abreast-to-stay-afloat/#comments</comments>
		<pubDate>Sat, 15 Oct 2011 12:50:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Professional Development]]></category>

		<guid isPermaLink="false">http://idosql.com/?p=222</guid>
		<description><![CDATA[Written by Luis Miguel – Originally published on October 15, 2011 A continuous learning effort is just one of a few constants across the different areas of the IT field. Thru the years I have, for the most part, satisfied the need for training thru self-study, with the occasional exception of an employer-sponsored week of [...]]]></description>
			<content:encoded><![CDATA[<p>Written by Luis Miguel – Originally published on October 15, 2011</p>
<p>A  continuous learning effort is just one of a few constants across the different areas of the IT field. Thru the years I have, for the most part,  satisfied the need for training thru self-study, with the occasional exception  of an employer-sponsored week of Oracle 10 or SQL Server 2005 administration at an authorized training facility, and my personal experience is that not even  official training at a local college matches the return on investment against  doing the study yourself.</p>
<div>
<p>I  recently took an offer from Brian Knight (famous BI author) and Pragmatic Works  for a three-day SSIS workshop around the corner in Ft. Lauderdale, the price  seemed reasonable and the content interesting. So I ended up &#8220;investing&#8221; 3 days of  vacation time and $300.00 out of my own pocket to attend this event and I don&#8217;t  regret it. This is my take on Brian Knight and the Pragmatic Works  workshop.</p>
</div>
<div>
<p>The  thing is worth it, money well spent, Brian knows this stuff, his classes are 100%  fat free, even his &#8220;stupid jokes&#8221; are good and few, so you end up with a day of  tasty substance. You even get some of your money back, Brian was very kind and threw in a couple of t-shirts for everyone, and so many books of his latest title (Microsoft Business Intelligence 24-Hour Trainer) that I think 80% of the class went home with one, they had doughnuts and coffee for breakfast and lunch was  decent.</p>
</div>
<div>
<p>This  particular workshop will not make you an SSIS developer, for that you need  longer training and some experience, but it will definitely get you started in  the right direction. The workshop covered the most important Data Flow Task  transformations, with real world examples and tips acquired by Brian thru the  years as a consultant, and this is probably the most valuable part of the  workshop, Brian is your buddy that has been in the trenches for a long time and  gives you that perspective and insight.</p>
</div>
<div>
<p>So  yeah, good experience overall, in the future I&#8217;ll definitely consider other more in-depth offers from Pragmatic Works. In the mean time I&#8217;ll stay &#8220;hitting the books&#8221; on my own, stay thirsty [for knowledge] my friends.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://idosql.com/2011/10/15/lifelong-learning-stay-abreast-to-stay-afloat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SQL Sever 2008 Database Extended Properties to Automate Database Management Tasks</title>
		<link>http://idosql.com/2011/06/12/using-sql-sever-2008-database-extended-properties-to-automate-database-management-tasks/</link>
		<comments>http://idosql.com/2011/06/12/using-sql-sever-2008-database-extended-properties-to-automate-database-management-tasks/#comments</comments>
		<pubDate>Sun, 12 Jun 2011 14:05:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Instance Administration]]></category>

		<guid isPermaLink="false">http://idosql.com/?p=211</guid>
		<description><![CDATA[Written by Luis Miguel &#8211; Originally published on June 12, 2011 Problem: Like any manual process, adding users to databases and setting their permissions on more than a few databases is a tedious and error-prone endeavor. By creating a couple of “admin” stored procedures, a DBA can automate this process to the point of being [...]]]></description>
			<content:encoded><![CDATA[<p>Written by Luis Miguel &#8211; Originally published on June 12, 2011</p>
<p>Problem:<br />
Like any manual process, adding users to databases and setting their permissions on more than a few databases is a tedious and error-prone endeavor. By creating a couple of “admin” stored procedures, a DBA can automate this process to the point of being able to execute this task in one fell swoop, at the query editor by typing a few words just once.</p>
<p>If you care for documentation [I do], SQL Server Extended Properties are very convenient when it comes to adding tags, or labels to objects. I particularly find very useful to mark databases with notes that describe their purpose or their level of security sensitivity, etc&#8230;</p>
<p>Once you have a standard for these documentation tags and you keep them updated they can be a huge helper for performing database administration tasks very effectively.</p>
<p>Here is a list of the components I’m using to build this solution. I’m keeping all these administrative objects in the (I hope this name is descriptive enough) UTILTY_ADMIN user database</p>
<p>1 &#8211; The table to keep a list of the databases that are currently online and have a some kind of Extended Property</p>
<p><font face="Courier New" size="2"><br />
<font color = "blue">USE</font>&nbsp;<font color = "maroon">utility_admin</font><br />
<font color = "blue">CREATE</font>&nbsp;<font color = "blue">TABLE</font>&nbsp;<font color = "maroon">extendedproperties</font><br />
&nbsp;&nbsp;<font color = "maroon">(</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">dbname</font>&nbsp;&nbsp;&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">255</font><font color = "maroon">)</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">ep_name</font>&nbsp;&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">128</font><font color = "maroon">)</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">ep_value</font>&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">128</font><font color = "maroon">)</font><br />
&nbsp;&nbsp;<font color = "maroon">)</font>&nbsp;<br />
</font></p>
<p>2 &#8211; The stored procedure that does the brunt of the work, querying the Extended Properties of each database and storing them in the UTILITY_ADMIN.dbo.ExtendedProperties table</p>
<p><font face="Courier New" size="2"><br />
<font color = "blue">USE</font>&nbsp;<font color = "maroon">utility_admin</font><br />
<font color = "blue">GO</font><br />
<font color = "blue">CREATE</font>&nbsp;<font color = "blue">PROCEDURE</font>&nbsp;<font color = "#FF0080"><b>Getextendedproperties</b></font>&nbsp;<font color = "#8000FF">@DatabaseName</font>&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">255</font><font color = "maroon">)</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "blue">NULL</font><br />
<font color = "blue">AS</font><br />
&nbsp;&nbsp;<font color = "blue">IF</font>&nbsp;<font color = "#8000FF">@DatabaseName</font>&nbsp;<font color = "blue">IS</font>&nbsp;<font color = "blue">NULL</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">SET</font>&nbsp;<font color = "#8000FF">@DatabaseName</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "fuchsia"><i>Db_name</i></font><font color = "maroon">(</font><font color = "maroon">)</font><br />
&nbsp;&nbsp;<font color = "blue">DECLARE</font>&nbsp;<font color = "#8000FF">@SQLText</font>&nbsp;<font color = "black"><i>NVARCHAR</i></font><font color = "maroon">(</font><font color = "black">2000</font><font color = "maroon">)</font><br />
&nbsp;&nbsp;<font color = "blue">IF</font>&nbsp;<font color = "fuchsia"><i>Object_id</i></font><font color = "maroon">(</font><font color = "red">N&#8217;tempdb.dbo.##temp_ExtendedProperties&#8217;</font><font color = "maroon">)</font>&nbsp;<font color = "blue">IS</font>&nbsp;<font color = "blue">NOT</font>&nbsp;<font color = "blue">NULL</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">DROP</font>&nbsp;<font color = "blue">TABLE</font>&nbsp;<font color = "maroon">##temp_extendedproperties</font><br />
&nbsp;&nbsp;<font color = "blue">CREATE</font>&nbsp;<font color = "blue">TABLE</font>&nbsp;<font color = "maroon">##temp_extendedproperties</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">(</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">ep_name</font>&nbsp;&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">128</font><font color = "maroon">)</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">ep_value</font>&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">128</font><font color = "maroon">)</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">)</font><br />
&nbsp;&nbsp;<font color = "blue">SET</font>&nbsp;<font color = "#8000FF">@SQLText</font>&nbsp;<font color = "silver">=</font><br />
<font color = "red">&#8216;INSERT&nbsp;INTO&nbsp;##temp_ExtendedProperties&nbsp;SELECT&nbsp;CAST(name&nbsp;AS&nbsp;VARCHAR(128)),&nbsp;CAST(value&nbsp;AS&nbsp;VARCHAR(128))&nbsp;FROM&nbsp;&#8217;</font><br />
<font color = "silver">+</font>&nbsp;<font color = "#8000FF">@databasename</font>&nbsp;<font color = "silver">+</font><br />
<font color = "red">&#8216;.sys.fn_listextendedproperty(default,&nbsp;default,&nbsp;default,&nbsp;default,&nbsp;default,&nbsp;default,&nbsp;default)&#8217;</font><br />
&nbsp;&nbsp;<font color = "green"><i>&#45;&#45;&nbsp;That&nbsp;is&nbsp;7&nbsp;defaults</i></font><br />
&nbsp;&nbsp;<font color = "blue">EXECUTE</font><font color = "maroon">(</font><font color = "#8000FF">@SQLText</font><font color = "maroon">)</font>&nbsp;<br />
</font></p>
<p>3 &#8211; An SQL Server Agent job that runs every hour so that the list of databases with extended properties stays up to date</p>
<p><font face="Courier New" size="2"><br />
<font color = "blue">TRUNCATE</font>&nbsp;<font color = "blue">TABLE</font>&nbsp;<font color = "maroon">utility_admin</font><font color = "silver">.</font><font color = "maroon">dbo</font><font color = "silver">.</font><font color = "maroon">extendedproperties</font><br />
<font color = "blue">EXEC</font>&nbsp;<font color = "blue">MASTER</font><font color = "silver">.</font><font color = "maroon">sys</font><font color = "silver">.</font><font color = "#FF0080"><b>Sp_msforeachdb</b></font><br />
<font color = "red">&#8216;INSERT&nbsp;INTO&nbsp;utility_admin.dbo.ExtendedProperties&nbsp;EXEC&nbsp;utility_admin.dbo.GetExtendedProperties&nbsp;?&#8217;</font>&nbsp;<br />
</font></p>
<p>4 &#8211; UTILTIY_ADMIN.dbo.dbaManageUserRole &#8211; This is the stored procedure you are going to execute to actually add the user and set his/her permissions. It requires three parameters, the name of the user, the name of the extended property and the value of the extended property. I have hardwired the db_datareader role into this procedure but with a little bit of imagination you could also add the role as a parameter and make it even more flexible.</p>
<p><font face="Courier New" size="2"><br />
<font color = "blue">CREATE</font>&nbsp;<font color = "blue">PROCEDURE</font>&nbsp;<font color = "#FF0080"><b>Dbamanageuserrole</b></font>&nbsp;<font color = "#8000FF">@user</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">64</font><font color = "maroon">)</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "#8000FF">@ep_name</font>&nbsp;&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">128</font><font color = "maroon">)</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "#8000FF">@ep_value</font>&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">128</font><font color = "maroon">)</font><br />
<font color = "blue">AS</font><br />
&nbsp;&nbsp;<font color = "blue">DECLARE</font>&nbsp;<font color = "#8000FF">@dbname</font>&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">128</font><font color = "maroon">)</font><br />
&nbsp;&nbsp;<font color = "blue">DECLARE</font>&nbsp;<font color = "#8000FF">@adduser</font>&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">512</font><font color = "maroon">)</font><br />
&nbsp;&nbsp;<font color = "blue">DECLARE</font>&nbsp;<font color = "#8000FF">@addrole</font>&nbsp;<font color = "black"><i>VARCHAR</i></font><font color = "maroon">(</font><font color = "black">512</font><font color = "maroon">)</font><br />
&nbsp;&nbsp;<font color = "blue">DECLARE</font>&nbsp;<font color = "maroon">dbcursor</font>&nbsp;<font color = "blue">CURSOR</font>&nbsp;<font color = "blue">FOR</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">SELECT</font>&nbsp;<font color = "maroon">dbname</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">FROM</font>&nbsp;&nbsp;&nbsp;<font color = "maroon">utility_admin</font><font color = "silver">.</font><font color = "maroon">dbo</font><font color = "silver">.</font><font color = "maroon">extendedproperties</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">WHERE</font>&nbsp;&nbsp;<font color = "maroon">ep_name</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "#8000FF">@ep_name</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AND</font>&nbsp;<font color = "maroon">ep_value</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "#8000FF">@ep_value</font><br />
&nbsp;&nbsp;<font color = "blue">OPEN</font>&nbsp;<font color = "maroon">dbcursor</font><br />
&nbsp;&nbsp;<font color = "blue">FETCH</font>&nbsp;<font color = "blue">NEXT</font>&nbsp;<font color = "blue">FROM</font>&nbsp;<font color = "maroon">dbcursor</font>&nbsp;<font color = "blue">INTO</font>&nbsp;<font color = "#8000FF">@dbname</font><br />
&nbsp;&nbsp;<font color = "blue">WHILE</font>&nbsp;<font color = "fuchsia"><i>@@FETCH_STATUS</i></font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "black">0</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">BEGIN</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">SET</font>&nbsp;<font color = "#8000FF">@adduser</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "red">&#8216;USE&nbsp;&#8217;</font>&nbsp;<font color = "silver">+</font>&nbsp;<font color = "#8000FF">@dbname</font>&nbsp;<font color = "silver">+</font>&nbsp;<font color = "red">&#8216;;&nbsp;CREATE&nbsp;USER&nbsp;&#8217;</font>&nbsp;<font color = "silver">+</font>&nbsp;<font color = "#8000FF">@user</font>&nbsp;<font color = "silver">+</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "red">&#8216;&nbsp;FOR&nbsp;LOGIN&nbsp;&#8217;</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "silver">+</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "#8000FF">@user</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">SET</font>&nbsp;<font color = "#8000FF">@addrole</font>&nbsp;<font color = "silver">=</font>&nbsp;<font color = "red">&#8216;USE&nbsp;&#8217;</font>&nbsp;<font color = "silver">+</font>&nbsp;<font color = "#8000FF">@dbname</font>&nbsp;<font color = "silver">+</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "red">&#8216;;&nbsp;EXEC&nbsp;sp_addrolemember&nbsp;N&#8221;db_datareader&#8221;,&nbsp;&#8217;</font>&nbsp;<font color = "silver">+</font>&nbsp;<font color = "#8000FF">@user</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">EXECUTE</font><font color = "maroon">(</font><font color = "#8000FF">@adduser</font><font color = "maroon">)</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">EXECUTE</font><font color = "maroon">(</font><font color = "#8000FF">@addrole</font><font color = "maroon">)</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">FETCH</font>&nbsp;<font color = "blue">NEXT</font>&nbsp;<font color = "blue">FROM</font>&nbsp;<font color = "maroon">dbcursor</font>&nbsp;<font color = "blue">INTO</font>&nbsp;<font color = "#8000FF">@dbname</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">END</font><br />
&nbsp;&nbsp;<font color = "blue">CLOSE</font>&nbsp;<font color = "maroon">dbcursor</font><br />
&nbsp;&nbsp;<font color = "blue">DEALLOCATE</font>&nbsp;<font color = "maroon">dbcursor</font>&nbsp;<br />
</font></p>
<p>Now we are ready to enjoy the rewards of our hard work time and time again. Here is the command I used to add the user ‘canela’ as a ‘db_datareader’ to all the databases I have tagged with ‘application_’ ‘reporting_’</p>
<p><font face="Courier New" size="2"><br />
<font color = "blue">EXEC</font>&nbsp;<font color = "#FF0080"><b>Dbamanageuserrole</b></font><br />
&nbsp;&nbsp;<font color = "maroon">canela</font><font color = "silver">,</font><br />
&nbsp;&nbsp;<font color = "maroon">application_</font><font color = "silver">,</font><br />
&nbsp;&nbsp;<font color = "maroon">reporting_</font>&nbsp;<br />
</font></p>
<p>Here is a picture of one of my lab servers showing a long list of dummy databases on the left pane and a shorter result list of the ones with extended properties on the bottom right side.</p>
<p><a href="http://idosql.com/wp-content/uploads/2011/06/database_extended_properties.png"><img class="aligncenter size-medium wp-image-215" title="database_extended_properties" src="http://idosql.com/wp-content/uploads/2011/06/database_extended_properties-300x168.png" alt="" width="300" height="168" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://idosql.com/2011/06/12/using-sql-sever-2008-database-extended-properties-to-automate-database-management-tasks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to run/debug Visual Studio 2010 websites in IIS 7 instead of the default (Cassini) development web server</title>
		<link>http://idosql.com/2011/05/25/181/</link>
		<comments>http://idosql.com/2011/05/25/181/#comments</comments>
		<pubDate>Wed, 25 May 2011 17:13:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP .Net Development]]></category>

		<guid isPermaLink="false">http://idosql.com/?p=181</guid>
		<description><![CDATA[Written by Luis Miguel – Originally published on May 25, 2011 Synopsis: When you create an ASP .NET 4 website in Visual Studio 2010 and do not modify any of its default settings as you run or debug this website from the IDE it starts and uses a special web server called Cassini, it does [...]]]></description>
			<content:encoded><![CDATA[<p>Written by Luis Miguel – Originally published on May 25, 2011</p>
<p>Synopsis:</p>
<p>When you create an ASP .NET 4 website in Visual Studio 2010 and do not modify any of its default settings as you run or debug this website from the IDE it starts and uses a special web server called Cassini, it does not run in the full blown, professional grade Windows web server (IIS 7)</p>
<p>Microsoft had many reasons to ship this special web server and have it run by default when Visual Studio and Visual Web Developer start a debug session on a project, but I do see a couple of issues with this:</p>
<p>1st &#8211; In the real world applications use IIS 7 not Cassinni, so I want to run/debug/test in IIS 7 not Cassini</p>
<p>2nd &#8211; Cassini is only available while IDE is running, and it shuts down when you close Visual Studio. I want to be able to use the website and test it at any time, directly from any local browser or remotely from other workstations over the network, without having to keep a Visual Web Developer session open.</p>
<p>These two requirements seem very basic, I don’t feel comfortable testing a project that eventually will be deployed to production unless the site is proven to run stably on the web server that will be hosting it permanently, and I need the flexibility of an always up web server.</p>
<p>So, after a bit of research and some trial and error experimenting, I found the procedure listed below will satisfy this need.</p>
<p>1 &#8211; Create a file system folder (c:\websites\mysite<br />
2 &#8211; Create a website in IIS 7 that points to the folder you created in step 1<br />
3 &#8211; Create an ASP .NET 4.0 website project in Visual Studio 2010 and use the folder you created in step 1 as the target folder<br />
4 &#8211; Save the project<br />
5 &#8211; Modify the URL in Website Start&#8230;</p>
<p><a href="http://idosql.com/wp-content/uploads/2011/05/menu-website-start-options.jpg"><img class="aligncenter size-medium wp-image-201" title="menu website start options" src="http://idosql.com/wp-content/uploads/2011/05/menu-website-start-options-300x168.jpg" alt="" width="300" height="168" /></a></p>
<p>From now on in order to run the website from the IDE in debug mode you need to open Visual Studio with the command “Run as Administrator”</p>
<p>Or use the menu Debug &#8211; Attach to Process</p>
<p><a href="http://idosql.com/wp-content/uploads/2011/05/menu-debug-attach-to-process.jpg"><img class="aligncenter size-medium wp-image-203" title="menu debug attach to process" src="http://idosql.com/wp-content/uploads/2011/05/menu-debug-attach-to-process-300x203.jpg" alt="" width="300" height="203" /></a></p>
<p>6 &#8211; Debug the project in Visual Studio 2010 or try to browse the site in a browser window</p>
<p>If you receive the error message “Unrecognized attribute ‘targetFramework’”, make sure the application pool for the website “mysite” in ISS 7 is set to support the 4.0 .NET Framework</p>
<p style="text-align: left;"><a href="http://idosql.com/wp-content/uploads/2011/05/immediatly-after-you-create-the-website-in-iis-7.jpg"><img class="aligncenter size-medium wp-image-196" title="immediatly after you create the website in iis 7" src="http://idosql.com/wp-content/uploads/2011/05/immediatly-after-you-create-the-website-in-iis-7-300x161.jpg" alt="" width="300" height="161" /></a></p>
<p style="text-align: left;"><a href="http://idosql.com/wp-content/uploads/2011/05/set-the-application-pool-framework1.jpg"><img class="aligncenter size-full wp-image-189" title="set the application pool framework" src="http://idosql.com/wp-content/uploads/2011/05/set-the-application-pool-framework1.jpg" alt="" width="263" height="239" /></a></p>
<p><a href="http://idosql.com/wp-content/uploads/2011/05/iis-server-site-running.jpg"><img class="aligncenter size-medium wp-image-205" title="iis server site running" src="http://idosql.com/wp-content/uploads/2011/05/iis-server-site-running-300x186.jpg" alt="" width="300" height="186" /></a></p>
<p>Follow the next steps if you want to go a bit further and test the data access layer</p>
<ol>
<li>Add a database connection to your project</li>
<li>Add a database control to the page Default.aspx</li>
<li>Save the project</li>
<li>Debug the project in      Visual Studio 2010 or try to browse the site in a browser window</li>
</ol>
<p><a href="http://idosql.com/wp-content/uploads/2011/05/page-with-a-data-control3.jpg"><img class="aligncenter size-medium wp-image-194" title="page with a data control" src="http://idosql.com/wp-content/uploads/2011/05/page-with-a-data-control3-300x189.jpg" alt="" width="300" height="189" /></a></p>
<p>When I built the test for the data access layer on the 2nd environment [specs listed below] I ran into this problem:</p>
<p>‘Handler “PageHandlerFactory-Integrated” has a bad module “ManagePipelineHandler” in its module list’</p>
<p>To resolve it I ran the command<br />
c:\windows\Microsoft.NET\Framework\v4.030319\aspnet_regiis.exe –i</p>
<p>There are some explanations about this issue on the internet and even more than one way (command) to resolve it. I know I installed SQL Server 2008 Service Pack 1 after the .NET framework and ASP .NET 4 so that could have been the problem but the command listed above took care of it in a couple of seconds.</p>
<p>This procedure applies to &#8220;WEBSITE&#8221; projects, if you created an ASP .NET &#8220;application&#8221; project, most of this work can be very easily done thru the menu.</p>
<p>Technologies used:</p>
<p>1st Environment<br />
- Windows Server 2008 R2 Enterprise 64-bit<br />
- SQL Server 2008 R2 Standard 64-bit<br />
- Internet Information Service (IIS) 7<br />
- Visual Studio Professional 2010</p>
<p>2nd environment<br />
- Windows Server 2008 Standard 32-bit with Service Pack 2<br />
- SQL Server 2008 Standard 32-bit with Service Pack 1<br />
- Internet Information Services (IIS) 7<br />
- Visual Web Developer Express 2010</p>
]]></content:encoded>
			<wfw:commentRss>http://idosql.com/2011/05/25/181/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Workaround to bypass the 1000 records limit, set by ADSI when querying Active Directory using SQL Server</title>
		<link>http://idosql.com/2011/01/29/workaround-to-bypass-the-1000-records-limit-set-when-querying-active-directory-adsi-using-sql-server/</link>
		<comments>http://idosql.com/2011/01/29/workaround-to-bypass-the-1000-records-limit-set-when-querying-active-directory-adsi-using-sql-server/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 05:44:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Active Directory Query]]></category>

		<guid isPermaLink="false">http://idosql.com/?p=151</guid>
		<description><![CDATA[Written by Luis Miguel – Originally published on January 29, 2011 Who can benefit from this post? – This post does not go into the details of how to build a solution to query Active Directory using SQL Server. Instead it presents a workaround for people that are already querying Active Directory using SQL Server [...]]]></description>
			<content:encoded><![CDATA[<p>Written by Luis Miguel – Originally published on January 29, 2011</p>
<p>Who can benefit from this post? – This post does not go into the details of how to build a solution to query Active Directory using SQL Server. Instead it presents a workaround for people that are already querying Active Directory using SQL Server and are hitting the 1000 records barrier imposed by ADSI.</p>
<p>As always, this is a short and sweet post so all the information needed to perform certain actions will not be included here. However the article should give you enough information to help you resolve the issue at hand fairly quickly.</p>
<p>Really QUICK-AND-DIRTY solution: If you have access to modify Active Directory settings, increase the value of MaxPageSize from its default of 1000 to something that suits your needs, BUT please read <a href="http://jeftek.com/219/avoid-changing-the-maxpagesize-ldap-query-policy" target="_blank">Avoid changing the MaxPageSize LDAP query policy</a> to understand the possible consequences of this action, the author (unlike me) seems to know quite a bit about the topic.</p>
<p>For the rest of us – the ones that can only “view” Active Directory – read below.</p>
<p>The first time I had to work on a solution to query Active Directory using SQL Server I remember reading on the Internet a few posts talking about the 1000 records limit and at least one possible trick to bypass it. At the time it was not an issue for me, the AD implementation I was working with had less than 1000 users, so I didn’t pay attention to the specifics of the solution. I don’t know about you, but 99% percent of the time when I’m working on a project/task, there is barely enough time to get it out, let alone plan/build for “scalability”.</p>
<p>So here we are now with report consumers complaining about some user names missing from the “employee” list.</p>
<p>As I troubleshooted this issue, I noticed that there are a few user properties in AD that could break the dataset into chunks smaller than 1000 records, which I could then put together one at a time in a table and end up with the complete data set.</p>
<p>The property I choose to use was “whenCreated”, I could determine that if I added the filter “whenCreated &lt; 20100101000000.0Z” to the WHERE clause of the query, Active Directory would return about 900 records. To get the rest of the data set (close to 300 records) I changed the query to whenCrated GREATER THAN 20100101000000.0Z</p>
<p>Here is a copy of the two complete queries:<br />
<font face="Courier New" size="2"><br />
<font color = "blue">INSERT</font>&nbsp;<font color = "blue">INTO</font>&nbsp;<font color = "maroon">my_ad_users_list</font><br />
<font color = "blue">SELECT</font>&nbsp;<font color = "maroon">givenname</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">firstname</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">sn</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">lastname</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">initials</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">displayname</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">samaccountname</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "blue">ACCOUNT</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">telephonenumber</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">mobile</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">facsimiletelephonenumber</font>&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">fax</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">pager</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">mail</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">emailaddress</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">department</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">title</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">l</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">city</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">postalcode</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">ipphone</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">extension</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">physicaldeliveryofficename</font>&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">office</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "red">&#8216;my_domain&#8217;</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">domain</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "red">&#8216;regular&#8217;</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">usertype</font><br />
<font color = "blue">FROM</font>&nbsp;&nbsp;&nbsp;<font color = "fuchsia"><i>Openquery</i></font>&nbsp;<font color = "maroon">(</font><font color = "maroon">adsi</font><font color = "silver">,</font>&nbsp;<font color = "red">&#8216;SELECT&nbsp;givenname,&nbsp;sn,&nbsp;initials,&nbsp;displayname,&nbsp;sAMAccountName,&nbsp;telephoneNumber,<br />
&nbsp;mobile,&nbsp;facsimileTelephoneNumber,&nbsp;pager,&nbsp;mail,&nbsp;department,&nbsp;title,&nbsp;l,&nbsp;PostalCode,&nbsp;ipPhone,&nbsp;physicalDeliveryOfficeName</p>
<p>&nbsp;&nbsp;FROM&nbsp;&#8221;LDAP://ad_server_name.my_domain.my_company.corp&#8221;</p>
<p>&nbsp;&nbsp;WHERE&nbsp;userAccountControl=512&nbsp;AND&nbsp;objectCategory&nbsp;=&nbsp;&#8221;Person&#8221;&nbsp;AND&nbsp;objectClass&nbsp;=&nbsp;&#8221;user&#8221;<br />
&nbsp;AND&nbsp;whenCreated&nbsp;<&nbsp;''20100101000000.0Z'''</font><font color = "maroon">)</font><br />
<font color = "blue">WHERE</font>&nbsp;&nbsp;<font color = "maroon">givenname</font>&nbsp;<font color = "blue">IS</font>&nbsp;<font color = "blue">NOT</font>&nbsp;<font color = "blue">NULL</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AND</font>&nbsp;<font color = "maroon">sn</font>&nbsp;<font color = "blue">IS</font>&nbsp;<font color = "blue">NOT</font>&nbsp;<font color = "blue">NULL</font></p>
<p><font color = "blue">INSERT</font>&nbsp;<font color = "blue">INTO</font>&nbsp;<font color = "maroon">my_ad_users_list</font><br />
<font color = "blue">SELECT</font>&nbsp;<font color = "maroon">givenname</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">firstname</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">sn</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">lastname</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">initials</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">displayname</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">samaccountname</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "blue">ACCOUNT</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">telephonenumber</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">mobile</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">facsimiletelephonenumber</font>&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">fax</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">pager</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">mail</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">emailaddress</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">department</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">title</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">l</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">city</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">postalcode</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">ipphone</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">extension</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "maroon">physicaldeliveryofficename</font>&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">office</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "red">&#8216;my_domain&#8217;</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">domain</font><font color = "silver">,</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "red">&#8216;regular&#8217;</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AS</font>&nbsp;<font color = "maroon">usertype</font><br />
<font color = "blue">FROM</font>&nbsp;&nbsp;&nbsp;<font color = "fuchsia"><i>Openquery</i></font>&nbsp;<font color = "maroon">(</font><font color = "maroon">adsi</font><font color = "silver">,</font>&nbsp;<font color = "red">&#8216;SELECT&nbsp;givenname,&nbsp;sn,&nbsp;initials,&nbsp;displayname,&nbsp;sAMAccountName,&nbsp;telephoneNumber,<br />
&nbsp;mobile,&nbsp;facsimileTelephoneNumber,&nbsp;pager,&nbsp;mail,&nbsp;department,&nbsp;title,&nbsp;l,&nbsp;PostalCode,&nbsp;ipPhone,&nbsp;physicalDeliveryOfficeName</p>
<p>&nbsp;&nbsp;FROM&nbsp;&#8221;LDAP://ad_server_name.my_domain.my_company.corp&#8221;</p>
<p>&nbsp;&nbsp;WHERE&nbsp;userAccountControl=512&nbsp;AND&nbsp;objectCategory&nbsp;=&nbsp;&#8221;Person&#8221;&nbsp;AND&nbsp;objectClass&nbsp;=&nbsp;&#8221;user&#8221;<br />
&nbsp;AND&nbsp;whenCreated&nbsp;>&nbsp;&#8221;20100101000000.0Z&#8221;&#8217;</font><font color = "maroon">)</font><br />
<font color = "blue">WHERE</font>&nbsp;&nbsp;<font color = "maroon">givenname</font>&nbsp;<font color = "blue">IS</font>&nbsp;<font color = "blue">NOT</font>&nbsp;<font color = "blue">NULL</font><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color = "blue">AND</font>&nbsp;<font color = "maroon">sn</font>&nbsp;<font color = "blue">IS</font>&nbsp;<font color = "blue">NOT</font>&nbsp;<font color = "blue">NULL</font>&nbsp;<br />
</font><br />
Tools used</p>
<p>-          SQL Server 2005</p>
<p>-          ADExplorer</p>
]]></content:encoded>
			<wfw:commentRss>http://idosql.com/2011/01/29/workaround-to-bypass-the-1000-records-limit-set-when-querying-active-directory-adsi-using-sql-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Never trust auto generated tables</title>
		<link>http://idosql.com/2010/11/14/never-trust-auto-generated-tables/</link>
		<comments>http://idosql.com/2010/11/14/never-trust-auto-generated-tables/#comments</comments>
		<pubDate>Sun, 14 Nov 2010 13:08:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Data Types]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://idosql.com/?p=137</guid>
		<description><![CDATA[Written by Luis Miguel – Originally published on November 14, 2010. There is a huge difference between numeric data types. Without going into the details of how much memory they use or any other technicalities that could take a whole chapter in a book, let’s just say that you can, on purpose or accidentally, use a [...]]]></description>
			<content:encoded><![CDATA[<p>Written by Luis Miguel – Originally published on November 14, 2010.</p>
<p>There is a huge difference between numeric data types. Without going into the details of how much memory they use or any other technicalities that could take a whole chapter in a book, let’s just say that you can, on purpose or accidentally, use a larger than necessary numeric type For example Decimal, to store Integers, and your program will not crash and everything will “just work”.</p>
<p>But will it work efficiently? Could this be considered an optimized design? Not at all.</p>
<p>Consider this scenario</p>
<p>1 – You use an SSIS package to import data from Oracle into SQL Server and you tell the OLE DB Destination in the Data Flow Task to create new tables for you automatically<br />
2 – You know the application logic and you know that certain fields will never hold a value greater than 1000. What you don’t know is that these fields have been stored in Oracle using the Number(15,0) data type and SSIS set them in the destination table as Numeric(15,0)<br />
3 – You create a join between the two imported tables and start manipulating the data. As you run the update queries you notice that for certain logic using certain fields, updating a third table with about 20,000 records takes literally 3 seconds, while performing the same operation but using a different field takes close to 3 minutes. Obviously there is an enormous difference that at first look does not make any sense</p>
<p>As you start looking more deeply into the problem you notice that the query that runs very fast uses a column of the Integer data type, while the slow query uses a field set to Numeric(15,0).</p>
<p>Since you know that this is not the correct data type for the field you alter the table and change it to Integer. Now you run the two queries and they BOTH take 3 seconds.</p>
<p>Consider how this small (data type) lapse made a simple update operation run 60 times slower than it should have normally taken.</p>
<p>Lesson learned: “Trust but verify”. At least when performance matters, which is probably 99.99% of the time.</p>
<p>It sure is convenient to let SSIS create the table automatically for you. Having to manually create a table before bringing in the data could be very labor intensive, especially if the table has dozens of columns. Just go back and look at what SSIS did for you and make sure it is what you need.</p>
<p>Technologies used:<br />
- Oracle 9 on Solaris 9<br />
- SQL Server 2008 Standard on Windows Server 2008 Enterprise 64-bit<br />
- T-SQL<br />
- SSIS 2005<br />
- Microsoft Office (Excel) 2010 Professional</p>
]]></content:encoded>
			<wfw:commentRss>http://idosql.com/2010/11/14/never-trust-auto-generated-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a centralized backup monitoring solution</title>
		<link>http://idosql.com/2010/10/19/building-a-centralized-backup-monitoring-solution/</link>
		<comments>http://idosql.com/2010/10/19/building-a-centralized-backup-monitoring-solution/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 17:06:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://idosql.com/?p=35</guid>
		<description><![CDATA[Written by Luis Miguel – Originally published on October 19, 2010. A complete solution would include sending data from several servers into a central server, in this example I&#8217;m going to show you how to do it for one server. Also the final presentation of the data should use some form of reporting tool that [...]]]></description>
			<content:encoded><![CDATA[<p>Written by Luis Miguel – Originally published on October 19, 2010.</p>
<p>A complete solution would include sending data from several servers into a central server, in this example I&#8217;m going to show you how to do it for one server. Also the final presentation of the data should use some form of reporting tool that could display this data in a portal for easy consumption.</p>
<p>Step 1 &#8211; Create a table to store the backup information that will be captured periodically<br />
<code><br />
USE utility<br />
GO<br />
CREATE TABLE [dba].[backups](<br />
[backup_log_id] [int] IDENTITY(1,1) NOT NULL,<br />
[server_name] [nvarchar](64) NULL,<br />
[database_name] [nvarchar](128) NULL,<br />
[start_date] [datetime] NULL,<br />
[finish_date] [datetime] NULL,<br />
[expiration_date] [datetime] NULL,<br />
[backup_type] [nvarchar](64) NULL,<br />
[backup_size] [int] NULL,<br />
[physical_device_name] [nvarchar](128) NULL,<br />
[backupset_name] [nvarchar](128) NULL,<br />
[user_name] [nvarchar](64) NULL,<br />
[backup_log_date] [datetime] NULL,<br />
CONSTRAINT [PK_backups] PRIMARY KEY CLUSTERED(<br />
[backup_log_id] ASC<br />
)<br />
WITH(<br />
PAD_INDEX  = OFF,<br />
STATISTICS_NORECOMPUTE  = OFF,<br />
IGNORE_DUP_KEY = OFF,<br />
ALLOW_ROW_LOCKS  = ON,<br />
ALLOW_PAGE_LOCKS  = ON<br />
) ON [PRIMARY]<br />
) ON [PRIMARY]<br />
GO</code></p>
<p>Step 2 &#8211; Create the store procedure that will capture the data and save it to the backup information table<br />
<code><br />
USE msdb<br />
GO<br />
CREATE PROCEDURE [dbo].[usp_backup_status]<br />
AS<br />
BEGIN<br />
SET NOCOUNT ON;<br />
DECLARE @backup_log_date DATETIME<br />
SET @backup_log_date = (SELECT DATEADD(dd, DATEDIFF(dd, 0, GetDate()), 0))<br />
INSERT INTO utility.dba.backups<br />
SELECT RTRIM(CONVERT(CHAR(100), SERVERPROPERTY('Servername'))) AS Server,<br />
a.name,<br />
b.backup_start_date,<br />
d.backup_finish_date,<br />
b.expiration_date,<br />
CASE b.type<br />
WHEN 'D' THEN 'Database'<br />
WHEN 'L' THEN 'Log'<br />
WHEN 'I' THEN 'Differential database'<br />
WHEN 'F' THEN 'File or filegroup'<br />
WHEN 'G' THEN 'Differential file'<br />
WHEN 'P' THEN 'Partial'<br />
WHEN 'Q' THEN 'Differential partial'<br />
WHEN NULL THEN 'Null'<br />
END AS backup_type,<br />
b.backup_size / 1024000 AS backup_size,<br />
c.physical_device_name,<br />
b.name AS backupset_name,<br />
b.user_name,<br />
@backup_log_date AS backup_log_date<br />
FROM sys.databases AS a<br />
LEFT OUTER JOIN<br />
(SELECT<br />
database_name,<br />
MAX(backup_finish_date) AS backup_finish_date<br />
FROM msdb.dbo.backupset<br />
GROUP BY database_name<br />
) AS d<br />
ON a.name = d.database_name<br />
LEFT OUTER JOIN msdb.dbo.backupset AS b<br />
ON (a.name = b.database_name) AND (b.backup_finish_date = d.backup_finish_date)<br />
LEFT OUTER JOIN msdb.dbo.backupmediafamily AS c<br />
ON b.media_set_id = c.media_set_id<br />
ORDER BY a.name<br />
END</code></p>
<p>Step 3 &#8211; Create a job to run the stored procedure as frequently as needed</p>
<p>Step 4 &#8211; Query the &#8220;backups&#8221; table to see information about today&#8217;s backups<br />
<code><br />
SELECT<br />
[server_name],<br />
[database_name],<br />
[start_date],<br />
[finish_date],<br />
[expiration_date],<br />
[backup_type],<br />
[backup_size],<br />
[physical_device_name],<br />
[backupset_name],<br />
[user_name],<br />
[backup_log_date]<br />
FROM [utility].[dba].[backups]<br />
WHERE [backup_log_date] = (SELECT DATEADD(dd, DATEDIFF(dd, 0, GetDate()), 0))</code></p>
]]></content:encoded>
			<wfw:commentRss>http://idosql.com/2010/10/19/building-a-centralized-backup-monitoring-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)

Served from: idosql.com @ 2013-05-26 09:34:48 -->