Using SQLDMO to get information from SQL Server

Source: Internet
Author: User
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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.