Server
Summary:
MS SQL Server provides a very handy COM component "SQLDMO" to help us get and manage SQL Server. Here to provide some ideas and implementations
.
System Requirements:
Windows2000server
Vs.net RC3
SQL Server 2000
Text:
1. Using Sqldmo.dll in. Net
Path: >tlbimp Sqldmo.dll/out:rc3sqldmo.dll
Create a new C # project (WinForm, Library ...), add references, select Browse, find Rc3sqldmo.dll, join.
2. View the structure of the Rc3sqldmo.dll
Open Object View, select Rc3sqldmo, and you can browse all the definitions of properties, methods, and events.
3. Use of RC3SQLDMO
Get a connection:
Rc3sqldmo.sqlserver2 mysqlsvr = new Rc3sqldmo.sqlserver2class ();
MySQLSvr. Connect ("SQLServerName", "UID", "PWS");
Get Database Information:
Rc3sqldmo.databases mydbs=mysqlsvr.databases;
Rc3sqldmo.database2 mydb =new rc3sqldmo.database2class ();
Mydb=mydbs.item ("dbname", "owner"); or Mydb=mysqlsvr.databases.item ("dbname", "owner");
get information on tables and fields:
Rc3sqldmo. Tables mytbls= Mysqlsvr.databases.item ("dbname", "owner"). Tables;
Rc3sqldmo.table2 mytbl = new Rc3sqldmo.table2class ();
MYTBL = Mytbls.item ("tablename", "owner");
MYTBL = Mysqlsvr.databases.item ("dbname", "owner"). Tables.item ("tablename", "owner");
STRING[3] MyList = new String[3];
Rc3sqldmo.column2 myfield = new Rc3sqldmo.column2class ();
foreach (Object o in Mytbl.columns)
{
MyField = (rc3sqldmo.column2) o;
Mylist[0]=myfield.name;
MYLIST[1] = Myfield.datatype;
MYLIST[2] =myfield.length.tostring ();
}
to obtain information about a stored procedure::
Rc3sqldmo.storedprecudure2 MYSP = new Rc3sqldmo.storedprecudure2class ();
MYSP =MYSQLSVR.BATABASE.ITRM ("dbname", owner). Storedprecudures.item[b ("Spname", owner)]
discussion of the purpose::
dynamic management of SQL Server
Dynamic acquisition of table,storedprecudure structure information
You can also increase and modify the contents of all SQL Server object.