Get Computer Name

Dim host As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(Request.ServerVariables.Item("REMOTE_HOST"))

Dim strComputerName As String = host.HostName

Literal1.Text = strComputerName

ADODBD connection from ConnectionString

Dim connectionStringName As String = "TestConn"

Dim s As New StringBuilder

Dim a As ConnectionStringSettings = ConfigurationManager.ConnectionStrings(connectionStringName)

 

 

s.Append("ConnectionString: " & a.ConnectionString & "<br />")

s.Append("Name: " & (a.Name & "<br />"))

s.Append("ProviderName: " & a.ProviderName & "<br />")

 

 

Dim sqlConn As String = ConfigurationManager.ConnectionStrings(connectionStringName).ConnectionString

Dim connBuilder As SqlConnectionStringBuilder = New SqlConnectionStringBuilder(sqlConn)

s.Append("DataSource: " & connBuilder.DataSource & "<br />")

s.Append("InitialCatalog: " & connBuilder.InitialCatalog & "<br />")

s.Append("UserID: " & connBuilder.UserID & "<br />")

s.Append("Password: " & connBuilder.Password & "<br />")

s.Append("<hr />")

 

 

' Build an ADODBD connection string

Dim d As New StringBuilder

d.Append("Provider=SQLOLEDB;")

d.Append(String.Format("Data Source={0};", connBuilder.DataSource))

d.Append(String.Format("Initial Catalog={0};", connBuilder.InitialCatalog))

d.Append(String.Format("User Id={0};", connBuilder.UserID))

d.Append(String.Format("Password={0};", connBuilder.Password))

d.Append("<hr />")

 

 

Literal2.Text = s.ToString & d.ToString

Clean string from non numerical chars

var a:
a = 'hndj76hew4ht6';
a = Number(a.replace(/[^0-9-.]/g, ""));

Trapping HttpRequestValidationException

Protected Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Error
If Server.GetLastError.GetType Is GetType(System.Web.HttpRequestValidationException) Then
Server.ClearError()
Response.Redirect("ErrorTrap.aspx?Err=Naughty chars entered!")
'Response.Write("You entered inappropriate characters.<br>")
'Response.Write("Start Over or click Back.")
End If
End Sub

Target _blank in a .sitemap file

*.master.vb:
Protected Sub Menu1_MenuItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MenuEventArgs) Handles Menu1.MenuItemDataBound
e.Item.Target = CType(e.Item.DataItem, SiteMapNode)("target")
End Sub

Assign user to membership database roles

USE AspNetAjax
GO
EXEC
sp_addrolemember 'aspnet_Personalization_FullAccess', 'AspNetAjaxUser'
EXEC sp_addrolemember 'aspnet_Profile_FullAccess', 'AspNetAjaxUser'
EXEC sp_addrolemember 'aspnet_Roles_FullAccess', 'AspNetAjaxUser'
EXEC sp_addrolemember 'aspnet_Membership_FullAccess', 'AspNetAjaxUser'
EXEC sp_addrolemember 'aspnet_WebEvent_FullAccess', 'AspNetAjaxUser'

ASP Page body sample

<%@ Language="VBScript"%>
<%Option Explicit%>
<%
With Response
.Buffer=true
.Expires=0
.Clear
.CharSet="utf-8"
End With
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled ASP PAGE</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
background-color: #FFFFFF;
font-family: Verdana, Geneva, Arial, Tahoma, sans-serif;
font-size: 80%;
}
</style>
</head>
<body>
</body>
</html>

Kill all processes connected to a database

-- Kill all processes connected to a database.
use master;
declare @DatabaseName varchar(50);
declare @Spid varchar(20);
declare @Command varchar(50);
set @DatabaseName = 'MyDatabase';
print 'This query''s SPID: ' + convert(varchar, @@spid);
-- Select all SPIDs except the SPID for this connection
declare SpidCursor cursor for
select spid from master.dbo.sysprocesses
where dbid = db_id(@DatabaseName)
and spid != @@spid
open SpidCursor
fetch next from SpidCursor into @spid
while @@fetch_status = 0
begin
 print 'Killing process: ' + rtrim(@spid);
 set @Command = 'kill ' + rtrim(@spid) + ';';
 print @Command;
 execute(@Command);
 fetch next from SpidCursor into @spid
end
close SpidCursor
deallocate SpidCursor

Grant execute on all stored procedures in current db

Sample showing how to grant execute on all stored procedures for a specific user in specified database

USE [The Database Name Here]
DECLARE @name nvarchar(128)
DECLARE procCursor CURSOR FOR SELECT Name FROM sysobjects WHERE OBJECTPROPERTY(id, N'IsProcedure') = 1
 
OPEN procCursor
FETCH NEXT FROM procCursor INTO @name
 
WHILE @@FETCH_STATUS= 0
BEGIN
EXEC ('grant execute on [' +@name + '] to[The Database User Here]')
 
FETCH NEXT FROM procCursor INTO @name
END
 
CLOSE procCursor
DEALLOCATE procCursor
GO

Loop Session Variables

Sample showing how to loop through session variables.

<%
    For Each Item In Session.Contents
        Response.Write Item & " = " & Session(Item)
        Response.Write "<br />"     
    Next
%>