Software Technology Tips

SQL Server Management Objects (SMO) are objects designed for programmatic management of Microsoft SQL Server.
We can integrate SMO into any .NET based applications.
SMO is also compatible with SQL Server version 7.0, SQL Server 2000, and SQL Server 2005, which makes it easy to manage a multi-version environment.

Following code is used to run the Microsoft SQL Server Query files(script files) kept in
applications bin\Debug folder, with SMO.
VB.Net Code:
'   References used
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
'    Holds the script for creating tables in database.
Dim tableText As String
'   Path of table creation script in the project folder.
Dim tableFileName As String = My.Application.Info.DirectoryPath &

Dim srvMgmtServer As Server = New Server()
Dim srvConn As ServerConnection
Dim objDB As Database = srvMgmtServer.Databases("DatabaseName")
srvConn = srvMgmtServer.ConnectionContext
srvConn.ServerInstance = "ServerName"
srvConn.LoginSecure = False
If srvConn.LoginSecure = False Then
           srvConn.Login = "UserName"
           srvConn.Password = "Password"
End If
Using FileReader As New _
                tableText = FileReader.ReadToEnd
End Using
If tableText <> "" Then
End If

Related Tags:

Database, SQL Server, .NET

Author: Shibani Shubhadarshini


Let us Connect!

iso 9001 QA25 Red Herring STPI D&B Fastest Growing SME 2013 Award zinnov Nasscom

This site uses cookies. We respect your privacy.copyright (c) Mindfire Solutions 2007-2015. Login