Category Archives: Microsoft

SQL Server Transact-SQL

SQL SERVER – FIX : Error 15023: User already exists in current database.

Error 15023: User already exists in current database.

1) This is the best Solution.

First of all run following T-SQL Query in Query Analyzer. This will return all the existing users in database in result pan.

USE YourDB
GO
EXEC sp_change_users_login 'Report'
GO

Run following T-SQL Query in Query Analyzer to associate login with the username. ‘Auto_Fix’ attribute will create the user in SQL Server instance if it does not exist. In following example ‘ColdFusion’ is UserName, ‘cf’ is Password. Auto-Fix links a user entry in the sysusers table in the current database to a login of the same name in sysxlogins.

USE YourDB
GO
EXEC sp_change_users_login 'Auto_Fix', 'ColdFusion', NULL, 'cf'
GO

Run following T-SQL Query in Query Analyzer to associate login with the username. ‘Update_One’ links the specified user in the current database to login. login must already exist. user and login must be specified. password must be NULL or not specified

USE YourDB
GO
EXEC sp_change_users_login 'update_one', 'ColdFusion', 'ColdFusion'
GO

more details in http://blog.sqlauthority.com/2007/02/15/sql-server-fix-error-15023-user-already-exists-in-current-database/

IIS

Select all sites in IIS manager

You should be able to do:

cd %systemroot%\system32\inetsrv\

and then delete them

appcmd list site /xml | appcmd delete site /in
ASP.Net Microsoft

Datetime format / Globalization

<pre class="default prettyprint prettyprinted"><code><span class="tag"><configuration>
</span><span class="tag"><system.web>
</span><span class="tag"><globalization</span><span class="atn">culture</span><span class="pun">=</span><span class="atv">"en-GB"</span><span class="tag">/>
</span><span class="tag"></system.web>
</span><span class="tag"></configuration></span></code></pre>
Code Snippets .NET ASP.Net regex

ASP.Net Character Length Regular Expression Validators

ASP.Net RegularExpression Validators

Maximum character length Validation (Maximum 6 characters allowed)

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1"
Display = "Dynamic"
ControlToValidate = "TextBox1"
ValidationExpression = "^[\s\S]{0,6}$"
ErrorMessage="Maximum 6 characters allowed.">
</asp:RegularExpressionValidator>

Minimum character length Validation (Minimum 6 characters required)

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator2"
Display = "Dynamic"
ControlToValidate = "TextBox2"
ValidationExpression = "^[\s\S]{6,}$"
ErrorMessage="Minimum 6 characters required.">
</asp:RegularExpressionValidator>

Minimum and Maximum character length Validation (Minimum 2 and Maximum 6 characters required)

<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator3"
Display = "Dynamic"
ControlToValidate = "TextBox3"
ValidationExpression = "^[\s\S]{2,6}$"
ErrorMessage="Minimum 2 and Maximum 6 characters required.">
</asp:RegularExpressionValidator>

Alphanumeric with special Characters
Minimum length 7 and Maximum length 10. Characters allowed – a – z A – Z 0-9 ’@ & # .

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate=" txtPassword "
ValidationExpression="^[a-zA-Z0-9'@&#.\s]{7,10}$" />

Alphanumeric Only
Minimum length 7 and Maximum length 10. Characters allowed – a – z A – Z 0-9

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate=" txtPassword "
ValidationExpression="^[a-zA-Z0-9\s]{7,10}$" />

Alphabets Only
Minimum length 7 and Maximum length 10. Characters allowed – a – z A – Z

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate="txtPassword"
ValidationExpression="^[a-zA-Z]{7,10}$" />

Numeric Only
Minimum length 7 and Maximum length 10. Characters allowed – 0 – 9

<asp:RegularExpressionValidator ID="RegExp1" runat="server"
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate="txtPassword"
ValidationExpression="^[0-9]{7,10}$" />

source:
http://www.aspsnippets.com/Articles/ASP.Net-Regular-Expression-Validator-to-validate-Minimum-and-Maximum-Text-Length.aspx

VBA

VBA environment variables (ENVIRON)

To see a list of variables, create a sub:

 
Sub ListEnvironmentVariables()

    'each environment variable in turn
    Dim EnvironmentVariable As String
    
    'the number of each environment variable
    Dim EnvironmentVariableIndex As Integer
    
    'get first environment variables
    EnvironmentVariableIndex = 1
    EnvironmentVariable = Environ(EnvironmentVariableIndex)
    
    'loop over all environment variables till there are no more
    Do Until EnvironmentVariable = ""
    
    'get next e.v. and print out its value
    Debug.Print EnvironmentVariableIndex, EnvironmentVariable
    
    'go on to next one
    EnvironmentVariableIndex = EnvironmentVariableIndex + 1
    EnvironmentVariable = Environ(EnvironmentVariableIndex)
    
    Loop

End Sub
 

click menu “View” > “Immediate Window” and run it
Doesn’t work on macintosh

Private Sub Workbook_Open()
'Generates a GUID:
Sheet1.Cells(8, 3).Value = Mid$(CreateObject("Scriptlet.TypeLib").GUID, 2, 36)  

'environment variables:
Sheet1.Cells(11, 3).Value = Environ$("computername")  
Sheet1.Cells(12, 3).Value = Environ$("username")
Sheet1.Cells(13, 3).Value = Environ$("USERPROFILE")
 
MsgBox "Hello " & Environ$("username")

End Sub

on Macintosh Excel you can try a AppleScript, something like:

Function GetUserNameMac() As String
    Dim sMyScript As String

    sMyScript = "set userName to short user name of (system info)" & vbNewLine & "return userName"

    GetUserNameMac = MacScript(sMyScript)
End Function
IIS

IIS6 and Office 2007 MIME types

Error message:

 

    HTTP Error 404 – File or directory not found.
Internet Information Services (IIS)

Since Office 2007 was released after Windows Server 2003 and IIS6, IIS6 knows nothing about the new MIME types. So you need to manually add them:

Open Computer Management. (Right-click My Computer… Manage…)
Right-click Internet Information Services (IIS) Management… Properties…
Click MIME Types…
Click New… and add the following:

Extension     MIME Type
.xlsx     application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
.xltx     application/vnd.openxmlformats-officedocument.spreadsheetml.template
.potx     application/vnd.openxmlformats-officedocument.presentationml.template
.ppsx     application/vnd.openxmlformats-officedocument.presentationml.slideshow
.pptx     application/vnd.openxmlformats-officedocument.presentationml.presentation
.sldx     application/vnd.openxmlformats-officedocument.presentationml.slide
.docx     application/vnd.openxmlformats-officedocument.wordprocessingml.document
.dotx     application/vnd.openxmlformats-officedocument.wordprocessingml.template
.xlam     application/vnd.ms-excel.addin.macroEnabled.12
.xlsb     application/vnd.ms-excel.sheet.binary.macroEnabled.12

Exchange Tips & tricks

Exchange 2010 Database size

  1. Review the Purge items from the Recoverable Items folder. For details, see Clean Up the Recoverable Items Folder.
  2. Yes ESEutil /D is the command
  3. Safe?  Yes relatively, however, that said
    1. before you ever run any type of utility against an Exchange database you should back it up just in case something goes sideways.
    2. you will need 110% of the EDB size to perform the defrag and
    3. during the time its being defragged ALL users for that database will be unable to connect.
  4. Time, well this depends upon many factors, i.e. CPU, Disk Speed, Memory, other processes etc.  Basically I would plan to spend at least a full day on it.  But whatever you do you need to be patient because it does take time to complete.
  5. Personally I think you would be better off to create a NEW database and use the New-MoveRequest so check out these two articles  http://technet.microsoft.com/en-us/library/bb124495.aspx and http://technet.microsoft.com/en-us/library/bb124797.aspx since these will allow you to keep the system up and running while the data is being moved, however it does require more disk space until the process is done and then you can drop the old DB to gain all the space back.

http://social.technet.microsoft.com

Code Snippets Exchange Microsoft PowerShell

Export to CSV all your Exchange 2007/2010 Email Addresses

If you want to export all your users email addresses to a CSV so you can see who has which alias you can do this with this Power Shell Command


Get-Mailbox -ResultSize Unlimited
|Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses
|Where-Object {$_.PrefixString -ceq “smtp”}
| ForEach-Object {$_.SmtpAddress}}}
| Export-CSV c:\smtp.csv -NoTypeInformation

I have wrapped it here so just paste it in to Power Shell to run and this will show the Primary Email address and then all the alias addresses.

PowerShell Get-Mailbox display SMTP addresses


http://cscmblog.blogspot.pt/2012/02/export-to-csv-all-your-exchange.html

Code Snippets ASP.Net

Concatenate data fields as binding expression

Concatenate data fields as binding expression:

&lt;asp:label id=&quot;Label1&quot; runat=&quot;server&quot; 
     text='&lt;%# String.Format(&quot;{0}, {1}&quot;, Eval(&quot;ContactLastName&quot;), Eval(&quot;ContactFirstName&quot;)) %&gt;'&gt;
&lt;/asp:label&gt; 

how to implemented mailto in Hyperlink asp control inside the gridview:

&lt;asp:HyperLink id=&quot;hl1&quot; runat=&quot;server&quot; 
   NavigateUrl='&lt;%# Eval(&quot;Email&quot; , &quot;mailto:{0}&quot;) %&gt;'
   Text='&lt;%# Eval(&quot;Email&quot;) %&gt;'&gt;
&lt;/asp:HyperLink&gt;
Code Snippets .NET

Programmatically set the selected menu item in the Menu control

Mnu1.Items(1).Selected = True
Mnu1.FindItem(&quot;Nutrients&quot;).Selected = True
mnu1.Items(indexToSelect).Selected = True
MenuItem mi = this.Menu1.FindItem(&quot;Home&quot;);
 mi.Selected = true;
this.Menu1.Items[0].Selected = true;