Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi...

 

I'm developing a tool that, using SQLDMO, retrieves the objects from the available SQL Servers.

 

By now, I can retrieve anything but the relationships between tables!!

 

How can I do that?

 

 

Thanks!

 

Alex :p

Software bugs are impossible to detect by anybody except the end user.
Posted

Hi... thanks for the reply but...

 

If I connect to the Northwind DB, via SQLDMO, the Rules collection count = 0, but this DB have releationships between tables... :(

Software bugs are impossible to detect by anybody except the end user.
Posted
static void OutputDbTableRelationships()
{
SQLServerClass sqlServer = new SQLServerClass();
sqlServer.LoginSecure = true;
sqlServer.Connect("localhost", null, null);
_Database db = sqlServer.Databases.Item("Northwind", null);
foreach(_Table table in db.Tables)
{
	foreach(Key key in table.Keys)
	{
		if(key.Type != SQLDMO_KEY_TYPE.SQLDMOKey_Foreign)
			continue;
		Console.WriteLine("{0}.{1} references {2}.{3}", table.Name, key.KeyColumns.Item(1), key.ReferencedTable, key.ReferencedColumns.Item(1));
	}
}
}

Posted

Yeah... works!!!

Thanks!

 

Just to add... I had it donne calling a system sp:

 

Dim result As SQLDMO.QueryResults = _

db.ExecuteWithResults("USE " & Me.m_DataBase.Name & " ; EXEC sp_helpconstraint '" & Tables(t).Name & "'")

 

Thanks again.

 

Alex :p

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...