Author: joe

How to Load a Web Page from VisualBasic

This example illustrates how to call an external web page from a VB.NET application.

Dim webAddress As String = "http://www.example.com/"
Process.Start(webAddress)

This example illustrates how to load a webpage from within visual basic form.  After adding the WebBrowser control to your form, simply add the following code.

Webbrowser1.Navigate "www.vbforums.com"

 

 

Determine if a user belongs to a particular AD Group

This is the easiest way to determine if a user belongs to particular Active Directory user group using VB.NET without having to enumerate through all the user’s groups.

Public Function IsInGroup(ByVal GroupName As String) As Boolean
 Dim MyIdentity As System.Security.Principal.WindowsIdentity = System.Security.Principal.WindowsIdentity.GetCurrent()
 Dim MyPrincipal As System.Security.Principal.WindowsPrincipal = New System.Security.Principal.WindowsPrincipal(MyIdentity)
 Return MyPrincipal.IsInRole(GroupName)
End Function

SQL List of Database Sizes

The following SQL command lists each database on a given server shows its data file size.

with fs
as
 (
  select database_id, type, size * 8.0 / 1024 size
  from sys.master_files
 )
select 
 name,
 (select sum(size) from fs where type = 0 and fs.database_id = db.database_id) DataFileSizeMB,
 (select sum(size) from fs where type = 1 and fs.database_id = db.database_id) LogFileSizeMB
from sys.databases db

SQL Database Table Sizes

The following SQL command lists each table in a database and shows total row counts and disk spaced used.

SELECT 
  t.NAME AS TableName,
  s.Name AS SchemaName,
  p.rows AS RowCounts,
  SUM(a.total_pages) * 8 AS TotalSpaceKB, 
  SUM(a.used_pages) * 8 AS UsedSpaceKB, 
  (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM 
  sys.tables t
INNER JOIN 
  sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
  sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
  sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN 
  sys.schemas s ON t.schema_id = s.schema_id
WHERE 
  t.NAME NOT LIKE 'dt%' 
  AND t.is_ms_shipped = 0
  AND i.OBJECT_ID > 255 
GROUP BY 
  t.Name, s.Name, p.Rows
ORDER BY 
  t.Name