Monday, December 21, 2009

jQuery: Using a dialog on an ASP.Net UpdatePanel

I recently decided to start using UpdatePanel's in my code.  I know this is not the best way to write an AJAX enabled app, but it was the quickest path to making my product more responsive.  I also decided to integrate the use of jQuery in my app.  Along with that, I have decided to utilize the jQuery Dialog.

At first, it was a little difficult to get my head wrapped around how to best take advantage of this feature, but I eventually developed a process.  I have user controls that are placed on the page in UpdatePanels.  Sometimes those user controls need to pop up a dialog, so I will include the code for the dialog on the user control in a hidden DIV.

Now having a dialog in a DIV is not enough, you have to add javascript to create the dialog from your DIV, that's just how jQuery works, so I include code in an event handler that gets fired every time the UpdatePanel is updated (each user control uses the $(document).one("eventName", function() {}) syntax, but how that works is for another post).

Well I was noticing that I was having problems on the post backs when I had a dialog that was created from the user controls.  As it turns out, the problem was coming from the fact that each time the user control was refreshed, it was loading the jQuery Dialog into the DOM.  That meant that every post back puts a new copy of the dialog into the DOM causing problems with the values that post back to the server (not to mention a potentially bad memory leak).

I finally ended up with a solution that works great.  I have code that checks the DOM for the existence of the dialog prior to creating it and if it exists, I remove the first one.  Now this is not a problem for me, but if the dialog were to get updated in the post back, you would probably want to remove the last one and not the first one since the first one in the DOM is probably the one updated from the post back.

var dialogs = $("dailogSelector");
    if (dialogs.length == 2) {
        $(dialogs[0]).remove(); 
    }
}

This was something that after finding it seemed very obvious.  It was completely obvious once I fired up FireBug and saw that I had multiple copies of the dialog in memory.  However, prior to that, it seemed like there was some gremlin somewhere in the page life cycle stealing my post back values and it was very frustrating.  I only hope this post saves someone the frustration it caused me!

Saturday, December 12, 2009

SQLCMD Error: Login timeout expired

So I was automating the creation of a database and I was getting the following error:

Command
C:\sqlcmd -s "(local)SQLEXPRESS" -d TestDb -i MySql.sql

Error
HResult 0x2, Level 16, State 1
Named Pipes Provider: Could not open a connection to SQL Server [2].
Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections..
Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.

This was really confusing because all of the blogs that talked about this error were telling me to do things that I had already done.  I guess it is common to get this error, but the usual culprits were not at play with me.  I was stumped  I could not figure out why I had configured my DB Instance to accept remote connections and it was functioning properly, but I was still getting this error.

Well I finally found a post on this page that had the answer.  Let me say that it is all my fault, but I contend that if the SQLCMD program had better error messages, I would have figured out the problem quite quickly.  As it turns out, the -s parameter is to set the colseperator.  What I should have been using the -S parameter which is to set the server. 

C:\sqlcmd -S "(local)SQLEXPRESS" -d TestDb -i MySql.sql

Thursday, December 10, 2009

Review: Eye-FI Wireless SD Memory Card




I recently bought a new digital camera because I was excited about the Eye-Fi Wireless SD Memory card.  I had a friend who was raving about this card because it will automatically use available WI-FI to upload images to your desktop as well as to a number of online photo album sites.

I originally had a Sony digital camera and if you have one, you know that you can't use an SD memory card with it.  So, I went out and bought a new camera.  I think the camera is great and maybe I will write a post about it later, but not now.

Anyways, I get home and plug the SD card into the card reader and plug it into my USB port after installing the Eye-Fi software.  Well it comes up and tells me the card is bad and they will gladly ship one out to me.  I debated returning the card to the store, but decided it wasn't that urgent.  They said it would ship 5 day ground within 3 business days.  For my trouble, they are going to send me a $15 credit for their online store.

Unfortunately, I believed them.  After 7 business days, I called them because it doesn't usually take 5 days to get 5 day ground mail.  As it turns out, it had not shipped yet.  The guy told me it would go out the next day and I was ok with that.  Well that was on Wednesday.  On Tuesday of the next week I had not received an email from them and suspected it had not shipped.

I called them on check on my shipment.  They said it had shipped on Saturday.  I finally received it on Wednesday.  So I bought this card on 11/21 and it was defective.  I did not receive a good card until 12/10 when they claimed it would take a maximum of 8 working days to get it.


Now this doesn't seem so bad thus far.  So I was telling  my friend who originally told me about the card of this experience.  He was offering to let me borrow his Eye-Fi card after I explained my problems.  It turns out he had the same problem.

In conclusion, I am still using the card and it will probably be a nice thing to have.  I am notorious for taking pictures and never taking them off of my camera.  As for the quality of the card and the support of the card, I don't have very high hopes.  I give this card 6 out of 10.  I will let you know if I change my mind after using it more.

Saturday, December 5, 2009

IIS Virtual Directory Properties

As an update to my post on IIS Web Server Properties, here is a list of properties for Virtual Directories.

If you are interested in the code, I wrote it in PowerShell.  Here it is:

function List-VirtualDirectoryProps() { 
$virtualDirectory = New-Object System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1/Root/stb1")
 $virtualDirectorySchema = New-Object System.DirectoryServices.DirectoryEntry($virtualDirectory.Schema)
 foreach ($propName in $virtualDirectorySchema.OptionalProperties) {
  $prop = $virtualDirectory.Properties[$propName]
  $value = $prop.Value
  $type = ""
  if ($value) {
   $type = $value.GetType().ToString()
  }
  $out = new-object psobject
  $out | add-member noteproperty Name $prop.PropertyName
  $out | add-member noteproperty Type $type
  write-output $out
 }
}

Common Properties

Name
Type
AccessExecute

AccessFlags
int
AccessNoPhysicalDir

AccessNoRemoteExecute

AccessNoRemoteRead

AccessNoRemoteScript

AccessNoRemoteWrite

AccessRead
bool
AccessScript
bool
AccessSource

AccessSSL

AccessSSL128

AccessSSLFlags

AccessSSLMapCert

AccessSSLNegotiateCert

AccessSSLRequireCert

AccessWrite

AdminACLBin

AnonymousPasswordSync
bool
AnonymousUserName
string
AnonymousUserPass

AppAllowClientDebug

AppAllowDebugging

AppFriendlyName

AppIsolated

AppOopRecoverLimit
int
AppPackageID

AppPackageName

AppPoolId
string
AppRoot
string
AppWamClsid

AspAllowOutOfProcComponents
bool
AspAllowSessionState
bool
AspAppServiceFlags

AspBufferingLimit
int
AspBufferingOn
bool
AspCalcLineNumber
bool
AspCodepage

AspDiskTemplateCacheDirectory
string
AspEnableApplicationRestart
bool
AspEnableAspHtmlFallback

AspEnableChunkedEncoding
bool
AspEnableParentPaths

AspEnableSxs

AspEnableTracker

AspEnableTypelibCache
bool
AspErrorsToNTLog

AspExceptionCatchEnable
bool
AspExecuteInMTA

AspKeepSessionIDSecure
int
AspLCID

AspLogErrorRequests
bool
AspMaxDiskTemplateCacheFiles
int
AspMaxRequestEntityAllowed
int
AspPartitionID

AspProcessorThreadMax
int
AspQueueConnectionTestTime
int
AspQueueTimeout
int
AspRequestQueueMax
int
AspRunOnEndAnonymously
bool
AspScriptEngineCacheMax
int
AspScriptErrorMessage
string
AspScriptErrorSentToBrowser
bool
AspScriptFileCacheSize
int
AspScriptLanguage
string
AspScriptTimeout
int
AspSessionMax
int
AspSessionTimeout
int
AspSxsName

AspTrackThreadingModel

AspUsePartition

AuthAnonymous
bool
AuthBasic

AuthFlags
int
AuthMD5

AuthNTLM

AuthPassport

AuthPersistence
int
AuthPersistSingleRequest
bool
AzEnable

AzImpersonationLevel

AzScopeName

AzStoreName

CacheControlCustom

CacheControlMaxAge

CacheControlNoCache

CacheISAPI
bool
CGITimeout
int
ContentIndexed

CreateCGIWithNewConsole

CreateProcessAsUser
bool
DefaultDoc
string
DefaultDocFooter

DefaultLogonDomain

DirBrowseFlags
int
DirBrowseShowDate
bool
DirBrowseShowExtension
bool
DirBrowseShowLongDate

DirBrowseShowSize
bool
DirBrowseShowTime
bool
DisableStaticFileCache

DoDynamicCompression

DontLog

DoStaticCompression

EnableDefaultDoc
bool
EnableDirBrowsing

EnableDocFooter

EnabledProtocols

EnableReverseDns

FrontPageWeb

HttpCustomHeaders
string
HttpErrors
object[]
HttpErrorsExistingResponse

HttpExpires
string
HttpPics

HttpRedirect

IPSecurity
__Comobject
KeyType
string
LogonMethod
int
MaxRequestEntityAllowed
int
MimeMap

NTAuthenticationProviders
string
PassportRequireADMapping
int
Path
string
PoolIdcTimeout

Realm

RedirectHeaders

ScriptMaps
object[]
ShutdownTimeLimit
int
SSIExecDisable

UNCPassword

UNCUserName

UploadReadAheadSize
int
UseDigestSSP

Win32Error

IIS Web Server Properties

When I was trying to automate the creation of some websites and web applications, I was having a lot of trouble finding the attributes associated with a Web Application so I decided to write a script to output and ist them here.

If you are interested in the code, I wrote it in PowerShell.  Here it is:
function List-WebServerProps() {
    $server = New-Object System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/1")
    $serverSchema = New-Object System.DirectoryServices.DirectoryEntry($server.Schema)
    foreach ($propName in $serverSchema.OptionalProperties) {
        $prop = $server.Properties[$propName]
        $value = $prop.Value
        $type = ""
        if ($value) {
            $type = $value.GetType().ToString()
        }
        $out = new-object psobject
        $out | add-member noteproperty Name $prop.PropertyName
        $out | add-member noteproperty Type $type
        write-output $out
    }
}

Common Properties

Name Type
AccessFlags int
AccessSSLFlags
AnonymousUserName string
AppPoolId string
AuthFlags int
DefaultDoc string
DirBrowseFlags int
HttpCustomHeaders string
HttpErrors object[]
KeyType string
LogFileDirectory string
LogPluginClsid string
NTAuthenticationProviders string
RedirectHeaders
ScriptMaps object[]
ServerBindings string
ServerCommand int
ServerComment string
ServerState int
TraceUriPrefix
Win32Error

Complete List

Name Value
AccessExecute
AccessFlags System.Int32
AccessNoPhysicalDir
AccessNoRemoteExecute
AccessNoRemoteRead
AccessNoRemoteScript
AccessNoRemoteWrite
AccessRead System.Boolean
AccessScript System.Boolean
AccessSource
AccessSSL
AccessSSL128
AccessSSLFlags
AccessSSLMapCert
AccessSSLNegotiateCert
AccessSSLRequireCert
AccessWrite
AdminACLBin
AllowKeepAlive System.Boolean
AllowPathInfoForScriptMappings
AnonymousPasswordSync System.Boolean
AnonymousUserName System.String
AnonymousUserPass
AppAllowClientDebug
AppAllowDebugging
AppFriendlyName
AppIsolated System.Int32
AppOopRecoverLimit System.Int32
AppPackageID
AppPackageName
AppPoolId System.String
AppRoot
AppWamClsid
AspAllowOutOfProcComponents System.Boolean
AspAllowSessionState System.Boolean
AspAppServiceFlags
AspBufferingLimit System.Int32
AspBufferingOn System.Boolean
AspCalcLineNumber System.Boolean
AspCodepage
AspDiskTemplateCacheDirectory System.String
AspEnableApplicationRestart System.Boolean
AspEnableAspHtmlFallback
AspEnableChunkedEncoding System.Boolean
AspEnableParentPaths
AspEnableSxs
AspEnableTracker
AspEnableTypelibCache System.Boolean
AspErrorsToNTLog
AspExceptionCatchEnable System.Boolean
AspExecuteInMTA
AspKeepSessionIDSecure System.Int32
AspLCID
AspLogErrorRequests System.Boolean
AspMaxDiskTemplateCacheFiles System.Int32
AspMaxRequestEntityAllowed System.Int32
AspPartitionID
AspProcessorThreadMax System.Int32
AspQueueConnectionTestTime System.Int32
AspQueueTimeout System.Int32
AspRequestQueueMax System.Int32
AspRunOnEndAnonymously System.Boolean
AspScriptEngineCacheMax System.Int32
AspScriptErrorMessage System.String
AspScriptErrorSentToBrowser System.Boolean
AspScriptFileCacheSize System.Int32
AspScriptLanguage System.String
AspScriptTimeout System.Int32
AspSessionMax System.Int32
AspSessionTimeout System.Int32
AspSxsName
AspTrackThreadingModel
AspUsePartition
AuthAdvNotifyDisable
AuthAnonymous System.Boolean
AuthBasic
AuthChangeDisable
AuthChangeUnsecure
AuthFlags System.Int32
AuthMD5
AuthNTLM
AuthPassport
AuthPersistence System.Int32
AuthPersistSingleRequest System.Boolean
AzEnable
AzImpersonationLevel
AzScopeName
AzStoreName
Bindings
CacheControlCustom
CacheControlMaxAge
CacheControlNoCache
CacheISAPI System.Boolean
CertCheckMode
CGITimeout System.Int32
ClusterEnabled
ConnectionTimeout System.Int32
ContentIndexed
CreateCGIWithNewConsole
CreateProcessAsUser System.Boolean
DefaultDoc System.String
DefaultDocFooter
DefaultLogonDomain
DirBrowseFlags System.Int32
DirBrowseShowDate System.Boolean
DirBrowseShowExtension System.Boolean
DirBrowseShowLongDate
DirBrowseShowSize System.Boolean
DirBrowseShowTime System.Boolean
DisableSocketPooling System.Boolean
DisableStaticFileCache
DoDynamicCompression
DontLog
DoStaticCompression
EnableDefaultDoc System.Boolean
EnableDirBrowsing
EnableDocFooter
EnabledProtocols
EnableReverseDns
FrontPageWeb
HttpCustomHeaders System.String
HttpErrors System.Object[]
HttpErrorsExistingResponse
HttpExpires System.String
HttpPics
IPSecurity System.__ComObject
KeyType System.String
LogExtFileBytesRecv
LogExtFileBytesSent
LogExtFileClientIp System.Boolean
LogExtFileComputerName
LogExtFileCookie
LogExtFileDate
LogExtFileFlags System.Int32
LogExtFileHost
LogExtFileHttpStatus System.Boolean
LogExtFileHttpSubStatus
LogExtFileMethod System.Boolean
LogExtFileProtocolVersion
LogExtFileReferer
LogExtFileServerIp
LogExtFileServerPort
LogExtFileSiteName
LogExtFileTime System.Boolean
LogExtFileTimeTaken
LogExtFileUriQuery
LogExtFileUriStem System.Boolean
LogExtFileUserAgent
LogExtFileUserName
LogExtFileWin32Status
LogFileDirectory System.String
LogFileLocaltimeRollover
LogFilePeriod System.Int32
LogFileTruncateSize System.Int32
LogOdbcDataSource System.String
LogOdbcPassword
LogOdbcTableName System.String
LogOdbcUserName System.String
LogonMethod System.Int32
LogPluginClsid System.String
LogType System.Int32
MaxBandwidth System.Int32
MaxBandwidthBlocked System.Int32
MaxConnections
MaxEndpointConnections System.Int32
MaxRequestEntityAllowed System.Int32
MimeMap
Name Type
NTAuthenticationProviders System.String
PassportRequireADMapping System.Int32
PasswordCacheTTL System.Int32
PasswordChangeFlags
PasswordExpirePrenotifyDays
PoolIdcTimeout
ProcessNTCRIfLoggedOn System.Boolean
Realm
RedirectHeaders
RevocationFreshnessTime System.Int32
RevocationURLRetrievalTimeout
ScriptMaps System.Object[]
SecureBindings
ServerAutoStart System.Boolean
ServerBindings System.String
ServerCommand System.Int32
ServerComment System.String
ServerListenBacklog System.Int32
ServerListenTimeout System.Int32
ServerSize System.Int32
ServerState System.Int32
SetHostName
ShutdownTimeLimit System.Int32
SSIExecDisable
SSLAlwaysNegoClientCert
SSLCertHash
SslCtlIdentifier
SslCtlStoreName
SSLStoreName
TraceUriPrefix
UploadReadAheadSize System.Int32
UseDigestSSP
UseHostName
Win32Error


IIS Virtual Directory Properties

Optional

Name Type
AccessExecute
AccessFlags int
AccessNoPhysicalDir
AccessNoRemoteExecute
AccessNoRemoteRead
AccessNoRemoteScript
AccessNoRemoteWrite
AccessRead bool
AccessScript bool
AccessSource
AccessSSL
AccessSSL128
AccessSSLFlags
AccessSSLMapCert
AccessSSLNegotiateCert
AccessSSLRequireCert
AccessWrite
AdminACLBin
AnonymousPasswordSync bool
AnonymousUserName string
AnonymousUserPass
AppAllowClientDebug
AppAllowDebugging
AppFriendlyName
AppIsolated
AppOopRecoverLimit int
AppPackageID
AppPackageName
AppPoolId string
AppRoot string
AppWamClsid
AspAllowOutOfProcComponents bool
AspAllowSessionState bool
AspAppServiceFlags
AspBufferingLimit int
AspBufferingOn bool
AspCalcLineNumber bool
AspCodepage
AspDiskTemplateCacheDirectory string
AspEnableApplicationRestart bool
AspEnableAspHtmlFallback
AspEnableChunkedEncoding bool
AspEnableParentPaths
AspEnableSxs
AspEnableTracker
AspEnableTypelibCache bool
AspErrorsToNTLog
AspExceptionCatchEnable bool
AspExecuteInMTA
AspKeepSessionIDSecure int
AspLCID
AspLogErrorRequests bool
AspMaxDiskTemplateCacheFiles int
AspMaxRequestEntityAllowed int
AspPartitionID
AspProcessorThreadMax int
AspQueueConnectionTestTime int
AspQueueTimeout int
AspRequestQueueMax int
AspRunOnEndAnonymously bool
AspScriptEngineCacheMax int
AspScriptErrorMessage string
AspScriptErrorSentToBrowser bool
AspScriptFileCacheSize int
AspScriptLanguage string
AspScriptTimeout int
AspSessionMax int
AspSessionTimeout int
AspSxsName
AspTrackThreadingModel
AspUsePartition
AuthAnonymous bool
AuthBasic
AuthFlags int
AuthMD5
AuthNTLM
AuthPassport
AuthPersistence int
AuthPersistSingleRequest bool
AzEnable
AzImpersonationLevel
AzScopeName
AzStoreName
CacheControlCustom
CacheControlMaxAge
CacheControlNoCache
CacheISAPI bool
CGITimeout int
ContentIndexed
CreateCGIWithNewConsole
CreateProcessAsUser bool
DefaultDoc string
DefaultDocFooter
DefaultLogonDomain
DirBrowseFlags int
DirBrowseShowDate bool
DirBrowseShowExtension bool
DirBrowseShowLongDate
DirBrowseShowSize bool
DirBrowseShowTime bool
DisableStaticFileCache
DoDynamicCompression
DontLog
DoStaticCompression
EnableDefaultDoc bool
EnableDirBrowsing
EnableDocFooter
EnabledProtocols
EnableReverseDns
FrontPageWeb
HttpCustomHeaders string
HttpErrors object[]
HttpErrorsExistingResponse
HttpExpires string
HttpPics
HttpRedirect
IPSecurity __Comobject
KeyType string
LogonMethod int
MaxRequestEntityAllowed int
MimeMap
NTAuthenticationProviders string
PassportRequireADMapping int
Path string
PoolIdcTimeout
Realm
RedirectHeaders
ScriptMaps object[]
ShutdownTimeLimit int
SSIExecDisable
UNCPassword
UNCUserName
UploadReadAheadSize int
UseDigestSSP
Win32Error