Using SQL-DMO To Backup and Verify a Database

Getting Started

SQLDMO.SQLServer

The code for the SQLDMO.SQLServer object should look very familiar. It allows you to connect to a given SQL server using either SQL Server on Windows NT authentication. Take a look at the snippet below.

  <%
  
    Dim
   srv
  Set srv = Server.CreateObject("SQLDMO.SQLServer")
  srv.LoginTimeout = 15
  srv.Connect "servername", "username", "password"
%>

This code creates a connection to SQL Server using SQL Server authentication. To login using NT authentication set the LoginSecure property to TRUE. This will cause the username and password parameters to be ignored and your NT login information will be used.

SQLDMO.Database

We will use the SQLDMO.Database object to get a list of databases from the server. This information is used to complete a backup request form in the sample application. The snippet below demonstrates using this object to populate a combo box.

  <%
  
    Dim
   srv
  Dim objDB
  Set srv = Server.CreateObject("SQLDMO.SQLServer")
  srv.LoginTimeout = 15 
  srv.Connect "servername", "username", "password"
  Set objDB = Server.CreateObject("SQLDMO.Database")
%><SELECTname="fdatabase"><%For Each objDB In srv.Databases
    If objDB.SystemObject = FalseThen%><OPTION><%=objDB.Name%></OPTION><%End IfNext%></SELECT>

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Every language has an optimization operator. In C++ that operator is ‘//’”