.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Imran Ghani
Sohaib Khalid

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

execute script file from database

Posted By:Maverick       Posted Date: March 24, 2011    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

execute script file from database

Public Shared Function ExceuteScript(ByVal FilePath As String, Optional ByVal connectionKey As String = "SourceConnection") As Integer
        Dim db As Database
        Dim Server As String = AppSettings("Server")
        Dim UserName As String = AppSettings("userid")
        Dim Password As String = AppSettings("password")
        Dim DbName As String = AppSettings("DBName")

        Dim ScriptExeceute As New Process
        Dim osqlParams As String = ""
        db = DatabaseFactory.CreateDatabase(connectionKey)
        FilePath = """" + FilePath + """"
        osqlParams = String.Format("-S {0} -U {1} -P {2} -d {3} -i ", Server, UserName, Password, DbName)
        ScriptExeceute.StartInfo.FileName = "sqlcmd.exe"
            ScriptExeceute.StartInfo.Arguments = osqlParams & FilePath
            ScriptExeceute.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        Catch ex As Exception

        End Try
        Return 0
End Function


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend