C# and SQLDMO

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I dumped VB and adopted C# for this version of Visual Studio. My problem! I
am trying to reference an SQLDMO.Database object in C# like so:

private SQLDMO.Database dbcurrent;
private string dbname;

dbname = "Northwind";
dbcurrent = (SQLDMO.Database)sqlsvr.Databases.Item(dbname);

But I get this error : No overload for method 'Item' takes '1' arguments.

I was hoping to avoid iterating through the SQLDMO.Databases collection to
obtain the ID of the database I want, and reference my target database via
that ID.
e.g. dbcurrent = (SQLDMO.Database)sqlsvr.Databases.ItemByID(i);

Any suggestions? And thanks in advance
 
Are you looking for something like this

string dbName = "Northwind";

SQLDMO.Database db = new SQLDMO.Database();

SQLDMO.SQLServer srv = new SQLDMO.SQLServer();


srv.Name = "(local)";

srv.LoginSecure = true;

srv.Connect(null,null,null);



db = (SQLDMO.Database)srv.Databases.Item(dbName,null);

MessageBox.Show("I have in my hand this database - " + db.Name + " it is
this big " + db.Size.ToString());

srv.DisConnect();






--
 
Many thanks Allan.

Basicall this is what I was looking for :
(SQLDMO.Database)srv.Databases.Item(dbName,null); the null parameter to the
Item method.
 
Back
Top