Scenario
A parent document contains a frame that loads a file which content is dynamic and you want the frame to not scroll and autosize the height of the frame.
Solution
function autoResizeParent() {
// if no parent don't attempt to change
if (parent != null) {
var frameList = parent.document.body.getElementsByTagName("iframe");
// is there any frames?
if (frameList != null) {
for (var i = 0; i < frameList.length; i++) {
var srcName = frameList[i].src;
srcName = srcName.substr(srcName.lastIndexOf("/"));
var srcParent = document.location.pathname.substr(document.location.pathname.lastIndexOf("/"));
alert("Parent=" + srcParent + "\nFrame="+ srcName);
// found myself
if (srcParent == srcName) {
// set parent frame height to my height
frameList[i].height = document.body.offsetHeight;
// force scrolling off
frameList[i].scrolling = "no";
}
}
}
}
}
Scenario
Have some perl code that wants to access Microsoft SQL Server 2005. The SQL Server is configured to only allow SSL connections for security reasons.
Solution
Here are the parts you will need:
Resources
Microsoft guidance on accessing SQL Server with Perl
http://technet.microsoft.com/en-us/library/bb497071.aspx
Thanks for Brian on helping figure this out :) ... I am just the messenger.
Scenario
Download your favorite image (or create one) and you want to exchange files with the guest OS. You are running Wi-fi and have to use the wired connection as your virtual network. You can access your image just fine through the Hyper-V Virtual Machine connection app but it doesn't support accessing host folders.
Solution
Remote Desktop to the rescue! Yes I know, this is old news, but read on for the problem you may encounter.
Problem
You start up remote desktop and try to access via IP and/or host name and you get that it is not there. Hmmm....
Real Solution
The problem may be that by default Remote Desktop will try to auto-detect a remote desktop gateway. When you are connected to the internet or you LAN you may encounter one! Just go over to the options/Advanced and choose to NOT use a gateway and voila! it works!
Now you can change your settings to share local host drives with your remote session (your guest VM) and start sharing!
Many clients I have worked with simply use the IISReset.exe command to recycle applications. Although this may have the desired affect sometimes, there are many alternatives that are better. By no means is this an exhaustive list but will give you some options when a specific website is causing problems (i.e. hung, OOM). Stopping a website doesn't reset memory or the worker process it just stops the website from processing the requests. Therefore, the website "start/stop" actions are not listed below.
Single Web Application "resets"
- Recommended: Recycle the application pool of the specific website's application pool. With Windows Server 2003 SP1 the command line is iisapp.vbs: Reference: http://blogs.iis.net/chrisad/archive/2006/08/30/Recycling-Application-Pools-using-WMI-in-IIS-6.0.aspx. You can use a process id /p or an application id with /a.
Examples:
D:\WINDOWS>iisapp /p 596 /r
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Application pool 'DefaultAppPool' recycled successfully.
D:\WINDOWS>iisapp /a DefaultAppPool /r
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Application pool 'DefaultAppPool' recycled successfully.
Reseting ALL websites on a server (not recommended)
- Start and stop specific services for web services only (do not do the start commands if you are not recycling)
NET STOP W3SVC
NET STOP HTTPFilter (if having problems with SSL)
NET START HTTPFilter (if having problems with SSL)
NET START W3SVC
- Use IISReset /NOFORCE , this causes the system to not forceable terminate the internet services if timeout or error occurs. Note: this will reset all IIS services that are enabled: FTP, NNTP, WWW, IISAdmin, etc.
- IISReset (without /NOFORCE) causes a forceable stop if doesn't respond within 60s (the stop default can be changed via command line). This may lead to IIS configuration loss (http://support.microsoft.com/kb/286196). Note: this will reset all IIS services that are enabled: FTP, NNTP, WWW, IISAdmin, etc.
- Reboot the server. Not recommended and may cause signficant data loss. Note: this attempts to shutdown or forcably shutdown all applications on the server not just IIS related.
- Power cycle the server. Not recommended and may cause signficant data loss. Note: this is extremely dangerous and only to be used when all other options (even one's not listed above) have been tried.
Hope this helps ...
Ever tried to install a printer by just giving users a link? Well here is a small snippet of one way to do this. Please note that since you are interacting with the OS (outside the browser) that you may receive security warnings. This has been tested on Vista SP1 x86 32 bit with IE7.
Code
<html>
<head>
<script type="text/vbscript">
function AddP(pName)
msgbox "Start"
Set WshNetwork = CreateObject("Wscript.Network")
WshNetwork.AddWindowsPrinterConnection pName
msgbox "Finished"
end function
</script>
</head>
<body>
<a href='#' language="vbscript" onclick="AddP('\\Home-PC\HP Photosmart 3300 series')">Add printer</a>
</body>
</html>
Please note that above the a href should be ="#" not single quotes.
For those interested in installing VSTS and using with IIS7 on Vista (and possible with Win 7) you should follow the following instructions:
http://msdn.microsoft.com/en-us/library/aa964620.aspx
Scenario
You have a normalized table that has values in rows. Let's take an example that has a history table with an approved flag:
Date Approved DollarValue Customer
1/1/2008 Y 13.5 A
2/1/2008 N 12 A
3/1/2008 Y 14 A
1/1/2008 Y 11.5 B
2/1/2008 Y 9 B
3/1/2008 Y 17 B
1/1/2008 Y 13.5 C
2/1/2008 Y 29 C
3/1/2008 Y 18 C
You want to find know if all the customers with all 3 monthly values approved and the values are < 20. Now I know you can get at this result multiple ways but I just want to show how you can apply logic across rows.
First you know that there are 3 monthly records for all the months data and you are also looking for an approved.
SELECT DISTINCT Customer
FROM MyTable
WHERE Approved = 'Y' AND DollarValue < 20
GROUP BY Customer
HAVING COUNT(Customer) = 3
You should see an output with only Customer B.
Similar techniques can be applied for OR and NOT.
Scenario
Recently I ran into a security issue that has a simple fix. Here is the situation:
- SSIS Package that contains a Script Task
- Run SSIS package as a SQL Job
- Use a special credential/proxy for the step of executing the SSIS package
Results
In the SQL Job History Log you may find something like this ...
Code: 0x00000002 Source: XXXXX Script Task Description: The script threw an exception: Unable to generate a temporary class (result=1). error CS2001: Source file 'C:\WINDOWS\TEMP\yyyzzzxxx.N.cs' could not be found error CS2008: No inputs specified
Solution
Simple put,the VBA compiler has permissions to write the file into C:\windows\temp but your credential does not. Now the simple fix is to allow just read/read&execute/list permissions to C:\windows\temp and that will resolve the issue above. However, please not that there is a potential security risk in doing so as that this credential now has access to read all temp files in this directory. So be forewarned that this may not fit your situation.
Conclusion
Although not suggesting the ideal security solution, this may help you troubleshoot and further refine your strategy in running you SSIS package with a Script task with a custom credential/proxy.
I was working on a common scenario and found an interesting side effect. Applications typically have a listing page that get search criteria from a UI and passes to a stored procedure. In the procedure you often find statements like:
SELECT a,b,c,d
FROM MyTable
WHERE c = @SearchC AND d = @SearchD
Often times you need to join information to the main data that is the most current from a historical table. For example in SQL 2005.
SELECT t.*
FROM
(SELECT
ID
, Amt
, AmtDepositDate
, row_number() over (partition by ID order by ID, AmtDepositDate desc) as rn
FROM MoneyTable
) t
WHERE rn=1
I found that when you join the above query to the main search query above a weird optimization occurs in SQL 2005. I suspect (unconfirmed with product group) that a left join can't optmize the query with the over so it ends up do a sub select on all records every row in the main search.
The solution (in my case where there is small sets of data of < 5000 records), I create a table variable and select into the lasted record from the history table. Then I join the table variable to the main table search.
In my scenario with 2000 main records and 1 million history records the left join with the latest select (no table variable) took 5+ minutes. Using the table variables took 2 seconds for everything.
Here is a snippet of the overall solution:
DECLARE @MyTable table (
ID int
,Amt float
,AmtDepositDate datetime
)
INSERT INTO @MyTable
SELECT
t.ID
,t.Amt
, t.AmtDepositDate
FROM
(
SELECT
ID
, Amt
, AmtDepositDate
, row_number() over (partition by ID order by ID, AmtDepositDate desc) as rn
FROM MoneyTable
) t
WHERE rn=1
SELECT
MT2.ID
, MT2.Name
, MT2.City
FROM
MyTable2 MT2
LEFT JOIN @MyTable MT
ON MT2.ID = MT.ID
WHERE
c = @SearchC AND d = @SearchD
Anyone experience similar or can offer up an reason for the optimization?
Scenario
A table that contains several columns that you need to take and change into rows in order to normalize the data. With SQL Server 2005, a new T-SQL command UNPIVOT can help. An example table:
**Table called MyTable
FieldID FieldOne FieldTwo FieldThree
1 abc 3.40 2008-03-03 00:00:00.000
2 def 4.00 2008-01-02 00:00:00.000
**Table Design
FieldID is an integer
FieldOne is char(10)
FieldTwo is decimal(14,2)
FieldThree is a datetime
Sample Code
SELECT FieldId, FieldCode, FieldValue
FROM
(
SELECT FieldId,
CONVERT(varchar(50), RTRIM(FieldOne )) AS FieldOne,
CONVERT(varchar(50), FieldTwo) AS FieldTwo,
CONVERT(varchar(50), FieldThree) AS FieldThree
FROM SampleUnpivot
) MyTable
UNPIVOT
(FieldValue FOR FieldCode IN (FieldOne, FieldTwo, FieldThree))AS MyUnPivot
Results
FieldID FieldCode FieldValue
1 FieldOne abc
1 FieldTwo 3.40
1 FieldThree Mar 3 2008 12:00AM
2 FieldOne def
2 FieldTwo 4.00
2 FieldThree Jan 2 2008 12:00AM
Notes
- If you have differnt data types make sure they are of the same time in the UNPIVOT IN clause
- Make sure to include the "ID" field (FieldID column in example above) to determine original record relationship
I know several people have blogged about this and it is available in the help files somewhat. I thought I would just capture a quick note on what I sometimes use.
Scenario: Show me all the changes (history) for all files within a location in a team project on a server for a specified date range
Command Line:
tf history /server:http://MYTFSSERVER:8080 $/MYTEAMPROJECT/FOLDER /recursive /format:brief /user:* /version:D"04/28/2008"~D"04/29/2008" /noprompt
So if your server name was "TFS01" and the TeamProject name was "FinancialApp" and your folder was "main" then the command line would be:
tf history /server:http://TFS01:8080 $/FinancialApp/main /recursive /format:brief /user:* /version:D"04/28/2008"~D"04/29/2008" /noprompt
You can use the following to move your sharepoint location on your existing TFS Sharepoint sites or Repritng Services to another port or to another server. Note that you must have the Sharepoint site or Reporting Services already configured.
TFS 2005/2008: During Setup
- Copy msiproperty.ini from the install media from AT or ATDT folder to a folder of your choice i.e. C:\temp\msiproperty.ini
- Change the property: VSTF_WSSSQL_PORT from 80 to another port.
- Start setup.exe under the subfolder of the sku with a command line: d:\atdt\setup.exe /INIFILE=C:\temp\msiproperty.ini.
TFS 2005: Change ports on same server for Sharepoint
http://blogs.msdn.com/elyasse/archive/2006/02/14/532120.aspx
TFS 2008: Moving Team Project Portals to a Different Server Running SharePoint Products and Technologies
http://msdn2.microsoft.com/en-us/library/bb909655.aspx
TFS 2008: Alreday installed, just change Reporting Services or Sharepoint port
Just run TFSAdminUtil ConfigureConnections. The details are located: http://msdn2.microsoft.com/en-us/library/bb778396.aspx
Working with a friend at work, we were discussing how to create some SQL to go after records in a table and process in a farm of computers (processing cluster). After few minutes of thinking I came up with the following.
BEGIN TRAN MyTran
UPDATE TOP 1 [dbo].[SomeTable] WITH (READPAST,UPDLOCK)
SET [IsCompleted] = 1, @RowId = ID
WHERE [IsCompleted] = 0
-- Do som manual processing on the record @RowId
COMMIT TRAN MyTran
The transaction issues the locks and keeps everything ACID. The update writes or holds a lock on the 1st available record due to the READPAST hint and the UPDLOCK hint holds the lock until the commit tran. If you have 1 machine it works fine and if you add 1000 machines then each machine grabs 1 record and proesses it. It helps with multi-concurrency and blocking that might occur without the hints.
Now this is just a form of load balancing using SQL (smile).
Some things to consider ...
- Make sure you can recover your server and database prior to issuing these commands.
- Since I am generically calling a rountine you will receive errors on the system databases.
- Your database and log files must follow the convention of name=database name_log=log file name.
- This will force the reduction of your log files and you may not be able to recover unless you have done the appropriate database backup and log backup operations (I know this is repeating item 1 ... smile )
- If you have any better ways or improvements feel free to post a comment.
Enough with the disclaimers, here is the code:
declare @sqlstring nvarchar(1024)
SET @sqlstring='use ?;DBCC SHRINKFILE (?, TRUNCATEONLY);DBCC SHRINKFILE (?_log, TRUNCATEONLY);BACKUP LOG ? WITH TRUNCATE_ONLY;DBCC SHRINKFILE (?_log, TRUNCATEONLY);';
SELECT @sqlstring;
exec master.dbo.sp_MSforeachDB @command1=@sqlstring
Have you ever run across this error before when trying to delete or disable a SQL server job (or edit one):
Cannot add, update, or delete a job (or its steps or schedules) that originated from an MSX server.
This sometimes can happen if you rename a server to another name after you have created your jobs and you try to disable a SQL job. This may be fine if you use a management server, however if you are sure you do not have a management server and you want to fix it up continue to read on.
To inspect all your job information use this command.
use msdb
select * from sysjobs
To make all your jobs, owned so to speak, by the server, issue the following command after you make reasonable precautions (backups, backups, etc):
use
msdb
DECLARE @srv sysname
SET @srv = CAST(SERVERPROPERTY('ServerName') AS sysname)
select @srv
select * from sysjobs
UPDATE sysjobs SET originating_server = @srv
select * from sysjobs