Hello. I will export the database generated script for all objects, I want to make an installer that executes that script on the remote server, I think the installer must ask for sa password; anyway thats not the problem, How can I make with SMO execute an script file
Thanks

Execute installation script.
topinambour
(at first you must create a database)
Kunal Cheda
uclimng
It seems to be very difficult because I havent find good info about this.
Tks
Yaniv Feinberg
For something fancier that gets passwords and other user input and then runs the script, you would need to write a wrapper script/application to gather the user input and then send it off to the server.
Anoop.H.TVM
string script = System.IO.File.ReadAllText(file);
beso
using
System.IO;~~~~~~~~~~~~~~~
Server srv = new Server("MyServer");
string filePath = "c:\\create.sql";
FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
sr.Close();
srv.Databases["tempdb"].ExecuteNonQuery(s);
David Keaveny
Try
Dim SMOServer As New Microsoft.SqlServer.Management.Smo.Server(onServer)
SMOServer.ConnectionContext.ExecuteNonQuery(script)
Return True
Catch ex As Exception
Return False
End Try
End Function
Where onServer would be something like (local) or (local)\instance
This works fine for me for the most part since the end users generaly dont have the database connection open at the time. But if they do have it open, then you first need to kill all connections to your database. Also your script needs to look something like this:
USE [YourDBNameHere]
GO
YOUR SCRIPT
GO