Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want generate sqlscript and run sqlscript using vb.net any one can tell me how to do this i am using following code but he give me error: Failed to connect to server ..)

VB
Dim tableFileName As String = "D:\PharmaDbScript.sql"
Dim tableText As String
Dim srvMgmtServer As Server = New Server
Dim srvConn As ServerConnection
Dim osqlservers As String = oSQLConnection.ToString

Dim objDB As Database = srvMgmtServer.Databases(osqlservers)
srvConn = srvMgmtServer.ConnectionContext
srvConn.ServerInstance = SQLServer
srvConn.LoginSecure = False
If srvConn.LoginSecure = False Then
   srvConn.Login = "id"
   srvConn.Password = "password"
End If

Using FileReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(tableFileName)
   tableText = FileReader.ReadToEnd
End Using

If tableText <> "" Then
   objDB.ExecuteNonQuery(tableText)
End If
Posted
Updated 24-Nov-13 22:21pm
v3
Comments
walterhevedeich 26-Nov-13 22:09pm    
Can you post the complete error? I am thinking it has something to do about your login credentials.

 
Share this answer
 
Comments
manoj s sherje 26-Nov-13 23:28pm    
Thanks for reply but i want generate sql server database script using vb either c#
 
Share this answer
 
Comments
manoj s sherje 26-Nov-13 23:28pm    
Thanks for reply but i want generate sql server database script using vb either c#

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900