Hi all,
Being new to Visual Studio 2010 c#, I am trying to get to grips with
the basics. The following code
errors when running a script from sql server 2008 to create tables
against an existing database. the script does run ok if ran from,
within sql server 2008.
The code in my c# app taken from on line examples states;
string script = File.ReadAllText("C:\\Temp\\script.sql");
Microsoft.SqlServer.Management.Smo.Server server =
new Microsoft.SqlServer.Management.Smo.Server();
server.ConnectionContext.LoginSecure = false;
server.ConnectionContext.Login = UserId.Text;
server.ConnectionContext.Password = UserPw.Text;
server.ConnectionContext.ServerInstance =
SvrName.Text;
server.Databases["system22root"].ExecuteNonQuery(script);
UserId.Text, UserPw.Text and SvrName.Text come from the user entry
form and these do work if I just try to connect to the database.
However, when I run the above I get an error against the line
server.Databases["system22root"].ExecuteNonQuery(script);
Which states
FailedOperationException was unhandled and the next line says
ExecuteNonQuery failed for Database 'system22root
The database system22root does exist and the script does work within
sql server 2008.
Any help would be appreciated.
Cheers
Ian