Groups | Blog | Home
all groups > sql server programming > september 2003 >

sql server programming : SQLDMO question


William (Bill) Vaughn
9/1/2003 1:27:06 PM
Are you USEing the correct user database or are you getting a dump of the
tables in Master?

--
____________________________________
Bill Vaughn
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

[quoted text, click to view]

M
9/1/2003 9:41:59 PM
I am using SQLDMO in an attempt to get a list of all the tables in a
database.
I am able to get a list of all the system tables, but none of the user
tables. In fact, the call to dmosqlTables.ItemByID(i) fails for the user
tables with the error "The ID 'n' was not found in the Tables Collection,
where n is a number that is less than the Tables.Count value. For example,
the call may work for values of n when n = 1,2,3,4,6,8,9,10 but fail for n=
5,7
I would appreciate any incite into this problem
thank you very much
M



I wrote the folowing code in C#:
dmosqlCurrDB = (SQLDMO.Database2)dmosqlSqlServer.Databases.Item(strDatabase,
"dbo");

dmosqlTables = dmosqlCurrDB.Tables;

int count = dmosqlCurrDB.Tables.Count;

ArrayList al = new ArrayList();

for (int i=1; i <= count; i++)

{

try

{

dmosqlCurrTable = (SQLDMO.Table2)dmosqlTables.ItemByID(i);

}

catch (Exception e)

{

Console.WriteLine(e.Message);

continue;

}

al.Add((string)dmosqlCurrTable.Name);


Andrea Montanari
9/1/2003 10:59:06 PM
hi M,
"M" <raab@beethoven.com> ha scritto nel messaggio
news:%23PlfDkLcDHA.4020@tk2msftngp13.phx.gbl...
[quoted text, click to view]

instead of directly calling them by ID, I'd prefer iterating the table
collection with a standard
foreach oTb in dmosqlCurrDB.Tables (vb6 like)....
hth
Andrea Montanari
andrea.sql@virgilio.it
montanari_andrea@virgilio.it
http://www.asql.biz/DbaMgr.shtm
DbaMgr2k ver 0.4.0 - DbaMgr ver 0.50.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply

AddThis Social Bookmark Button