Hi
I'm getting Create Database failed 'tmpdb'
when I'm executing fallowing code
ServerConnection scon = new ServerConnection("local", "sa", "");
Server GSer=new Server(scon);
Database db2 = new Database(GSer, "xyz");
GSer.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql;
db2.Create();
Can Anybody help me in this?
Thanks in advance
hi,there should be an inner exception stating what the actual problem is. if you can′t find any more information, try to use the capture mode instead of the execution mode and execute the script in the SSMS Query Window. You will get a mote detailed explanation in here.
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de|||
Thanks jens
can I create database object in C# code.
|||
Its not comming now with
GSer.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql;
getting "ExecuteNonQuery failed for Database 'xyz'.
error when I'm trying to execute scripts on db like
StreamReader sw=new StreamReader("C:\\script.sql");
string script = sw.ReadToEnd();
db2.ExecuteNonQuery(script);
What the error in this
|||I am using SMO to create a database with this code
StreamReader sr = new StreamReader(@."C:\GestMed\Bases\Create_GestMed_Prod.sql");
string script = sr.ReadToEnd();
script = script.Replace("GestMed_Prod",nombase);
ComCr?erSite.Serveur.ConnectionContext.Connect();
try
{
ComCr?erSite.Serveur.Databases["master"].ExecuteNonQuery(script);
str = " Base " + nombase + " : cr?ation OK";
Ecrire_Journal(sw,str);
}
catch (Exception e)
{
str = " Erreur Cr?ate Base " + nombase;
Ecrire_Journal(sw,str);
str = " Message : " + e.Message;
sw.WriteLine(sw);
SuiviTxt.Text += str + nl;
if ( e.InnerException != null )
{
str = " InnerException : " + e.InnerException.Message;
sw.WriteLine(str);
sw.Flush();
SuiviTxt.Text += str + nl;
}
sw.Flush();
ComCr?erSite.Cr?? = false;
this.Refresh();
return false;;
}
ComCr?erSite.Serveur.Refresh();
That's working
Maybe you have forgotten to connect to the server
I am using a generic script where i'm able to choose the name of the database
GestMed_Prod ==> GestMedSite0Prod for example
I had some problems with SMO it's why i decided to build an installation textfile where i keep all messages Exception.Message and InnerException.Message
I hopthat it will be useful for you and excuse me for my poor english
Have a good day
|||Hi,
sorry for not keeping up quicker. You should use the capture mode to see the commands which are generated by the SMO framework:
SqlExecutionModes.CaptureSql
After catching the string[] of command you can see which commands are causing the errors.
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
Hi,
I guess you are trying to create a database on local server.
If that is the case please use (local) or . instead of local (notice paranthesis).
Ex:Microsoft.SqlServer.Management.Common.ServerConnection scon = new Microsoft.SqlServer.Management.Common.ServerConnection("(local)", "sa", "");
I executed your code with just this change and it worked fine for me. Hope this helps.
Thanks,
Sravanthi.
|||using the above code
i write dingdong.sql which is following
create database dingdong
go
use [dingdong]
go
create table test(name varchar(20));
go
create table test1(father varchar(21));
go
database created but table did not created, what is the reason
Thanks
|||
Sorry my problem solved,by using following code
StreamReader sr = new StreamReader(@."C:\jehan.sql");
string script = sr.ReadToEnd();
textBox1.Text = script;
Microsoft.SqlServer.Management.Smo.Server srvSql;
Microsoft.SqlServer.Management.Common.ServerConnection srvConn = new Microsoft.SqlServer.Management.Common.ServerConnection
(Global.ConnectionToDatabase1());
srvSql = new Server(srvConn);
srvSql.Databases["master"].ExecuteNonQuery(script);
Global.con1.Close();
No comments:
Post a Comment