Skip to main content

Posts

Showing posts with the label SQL Server

How to determine total number of open/active connections in Microsoft sql server

This shows the number of connections per each DB: SELECT DB_NAME(dbid) as DBName, COUNT(dbid) as NumberOfConnections, loginame as LoginName FROM sys.sysprocesses WHERE dbid > 0 GROUP BY dbid, loginame And this gives the total: SELECT COUNT(dbid) as TotalConnections FROM sys.sysprocesses WHERE dbid > 0 If you need more detail, run: sp_who2 'Active'

Restoring a Database using bak files and SQL Scripts alone

The following is the script to restore any database from a .bak file without using Sql Server Management Studio -- The database name in the restored bak file should be the same as the one given here RESTORE DATABASE [authserver] FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL11.LOCAL\MSSQL\Backup\database.bak' WITH FILE = 1, MOVE N'authserver' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.LOCAL\MSSQL\DATA\database.MDF', MOVE N'authserver_LOG' TO N'C:\Program Files\Microsoft SQL Server\MSSQL11.LOCAL\MSSQL\DATA\database.LDF', NOUNLOAD, REPLACE, STATS = 10 GO

Copy databases using SQL Server SMO

The following steps are required to perform the Copying a Database using SQL Server objects exposed to the .Net Framework by Microsoft. Net 1. Add reference to the project with the following DLL files, Microsoft.SqlServer.ConnectionInfo.dll Microsoft.SqlServer.Smo.dll Microsoft.SqlServer.SmoExtended.dll Microsoft.SqlServer.Management.Sdk.Sfc.dll These dlls are found in the following folder C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies 2. Define a source Db and then the target DB, the source db will be scanned and then its contents [structure & data] string sourceDB = "cs_notification_test"; string targetDB = "cs_notification_test1"; SqlConnectionStringBuilder connStringBuilder = new SqlConnectionStringBuilder(System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationConnectionString"].ConnectionString); ServerConnection conn = new ServerConnection(connStringBuilder.DataSource, connStringBuilder.UserID, connStr

Enabling The SQL Server To Be Accessed Across Machines Or From Remote Machine

Following steps are to be followed so that the SQL Server can be accessed across machines or be accessed from a remote machine via Sql Server Management Studio [SSMS] Enable the following 1) TCP/IP, 2) Shared Memory 3) Named Pipes from all programs> sql 2012 > configuration tools > sql server configuration manager > expand sql server network configuration > protocols for sql2012r2de Now, in the “Run” command, put Services.msc and then choose the SQL Server and then enable the SQL Server Browser service Now try connecting from any remote machine. Trackback:  http://stackoverflow.com/questions/5956926/unable-to-connect-to-a-sql-server-database-remotely