Extended Properties Not Showing Up

  • Thread starter Thread starter localhost
  • Start date Start date
L

localhost

I have created a table in MSSQL2K and added an Extended Property to
it.
I want the Extended Property to show up in the result DataSet. What
should I change to make this happen?

TSQL:


Create Table dbo.ZTestTable (
"ZTestTable_Id" int not null, "Col-1" varchar(184) null,
"Col-2" varchar(238) null
)
Go

Exec sp_addextendedproperty
'TableType', 'A test table.', 'user', dbo, 'table', [ZTestTable]
Go

Exec sp_addextendedproperty
'ColumnComment', 'ZTestTable primary key identifier.', 'user', dbo,
'table', [ZTestTable], 'column', [ZTestTable_Id]
Go

grant select on ZTestTable to public

Go



C#:

using System;
using System.Data;
using System.Data.OleDb;


class ExtenTest
{
[STAThread]
static void Main(string[] args)
{
DataSet outSet = new DataSet( "OutSet" );
string connString = "DATABASE=.........."

// string selectIt = "Select * From ::fn_listextendedproperty " +
"('TableType', 'user', 'dbo', 'table','ZTestTable',
null, null)";
string selectIt = "select * from ZTestTable";

OleDbConnection dbCn = new OleDbConnection( connString );
dbCn.Open();

OleDbDataAdapter dbAda = new OleDbDataAdapter( selectIt , dbCn
);
dbAda.Fill( outSet );
outSet.WriteXml( @"c:\extentest.xml" ,
XmlWriteMode.WriteSchema );

}
}



Thanks.
 
Hi localhost,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get extended properties of
a table and fill them to a DataSet. If there is any misunderstanding,
please feel free to let me know.

I have tried your code on my computer, However, I didn't see any exceptions
during running. The properties have been filled and written to the output
xml file. Could you let me know where the problem is?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
I looked at the serialized DataSet and do not see the extended
properties in the schema.

This is the output I get when I view extentest.xml:

<?xml version="1.0" standalone="yes" ?>
<OutSet>
<xs:schema id="OutSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="OutSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="ZTestTable_Id" type="xs:int" minOccurs="0" />
<xs:element name="Col-1" type="xs:string" minOccurs="0" />
<xs:element name="Col-2" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
</OutSet>

I see the table name and column names.
I do not see anything that says "ColumnComment" or "ZTestTable primary
key identifier.".
I want to pull back a result set from SQL Server and any Extended
properties for the
table and columns. I know they are in the DB. How do I get them into
my DataSet?

Thanks.
 
Hi localhost,

I have been following your steps, however, I didn't reproduce it.
XmlWriteMode.WriteSchema will write schema together with data into xml.
Please try to put a DataGrid on the form to display the DataSet. And use
Select * From ::fn_listextendedproperty ('TableType', 'user', 'dbo',
'table','ZTestTable',null, null) in Query Analyzer to check if the extend
properties have been added to the table. Please also make sure that you
have connected to the correct database.

The following is the xml file I have get with WriteXml.

<?xml version="1.0" standalone="yes"?>
<OutSet>
<xs:schema id="OutSet" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="OutSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="objtype" type="xs:string" minOccurs="0" />
<xs:element name="objname" type="xs:string" minOccurs="0" />
<xs:element name="name" type="xs:string" minOccurs="0" />
<xs:element name="value" msdata:DataType="System.Object,
mscorlib, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<Table>
<objtype>TABLE</objtype>
<objname>ZTestTable</objname>
<name>TableType</name>
<value>A test table.</value>
</Table>
</OutSet>

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
I used Query Analyzer and see that the Extended Properties show up for
both the table and the column ZTestTable_Id.

I do not understand how code that I run on my machine creates
completely different results on your machine. I am running .NET
Framework 1.1-SP1 on WinXP-SP1.

Please post the code that you ran, and please explain why the
ColumnComment Extended Attribute is not showing in your XMLized
DataSet.

Thanks.
 
Hi localhost,

The following is the code I am using.

DataSet outSet = new DataSet( "OutSet" );
string selectIt = "Select * From ::fn_listextendedproperty " +
"('TableType', 'user', 'dbo', 'table','ZTestTable',null, null)";

OleDbDataAdapter dbAda = new OleDbDataAdapter( selectIt ,
this.oleDbConnection1);
dbAda.Fill( outSet );
outSet.WriteXml( @"c:\extentest.xml", XmlWriteMode.WriteSchema );
this.dataGrid1.DataSource = outSet;

Both DataGrid and xml file shows the extended property values. You can see
it in the <table> tag of xml.

<Table>
<objtype>TABLE</objtype>
<objname>ZTestTable</objname>
<name>TableType</name>
<value>A test table.</value>
</Table>

I think you might not connecting to the correct database.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
I am connecting to the correct database.

You did not execute the code I posted, you altered it.


Line 14 of my C# code was commented out. I left it there
as a test to verify that the Extended Properties exist in
SQL Server, and to show you that I already know how to do
that.

Line 17 is not commented because that is the kind of
query I expect to run. I just want to query the DB,
and if any extended properties exist on the table
or column, I want them returned along with the result set.


I think you do not understand what I am asking. Is it
possible for you to get input from another MS engineer
or MVP?


Thanks.





_______ original message _______



I have created a table in MSSQL2K and added an Extended Property to
it.
I want the Extended Property to show up in the result DataSet. What
should I change to make this happen?

TSQL:


Create Table dbo.ZTestTable (
"ZTestTable_Id" int not null, "Col-1" varchar(184) null,
"Col-2" varchar(238) null
)
Go

Exec sp_addextendedproperty
'TableType', 'A test table.', 'user', dbo, 'table', [ZTestTable]
Go

Exec sp_addextendedproperty
'ColumnComment', 'ZTestTable primary key identifier.', 'user', dbo,
'table', [ZTestTable], 'column', [ZTestTable_Id]
Go

grant select on ZTestTable to public

Go



C#:

using System;
using System.Data;
using System.Data.OleDb;


class ExtenTest
{
[STAThread]
static void Main(string[] args)
{
DataSet outSet = new DataSet( "OutSet" );
string connString = "DATABASE=.........."

// string selectIt = "Select * From ::fn_listextendedproperty " +
"('TableType', 'user', 'dbo', 'table','ZTestTable',
null, null)";
string selectIt = "select * from ZTestTable";

OleDbConnection dbCn = new OleDbConnection( connString );
dbCn.Open();

OleDbDataAdapter dbAda = new OleDbDataAdapter( selectIt , dbCn
);
dbAda.Fill( outSet );
outSet.WriteXml( @"c:\extentest.xml" ,
XmlWriteMode.WriteSchema );

}
}



Thanks.
 
Not an MS engineer or MVP but I'll give it a try.

It looks like you expect to have extended properties returned just by using
a SELECT * FROM MaTable statement with the usual resultset. It just not the
way it works.

Remember that extended properties are tied to COLUMNS not ROWS. As such you
won't find an additional column with the extended properties values (and
that would have anyway the same value for all rows) as you seem to expect.
You'll have to query extended properties separately. The result set will
contains a row for each column and property.

You may want to describe what you want to do with extended properties.

IMO you'll have to do it as a two step process in your data layer :
- have the data layer returning extended properties for each COLUMN (using
fn_listextendedporperties)
- then return ROWS (using SELECT * FROM MaTable)

Hope it helps.

--

localhost said:
I am connecting to the correct database.

You did not execute the code I posted, you altered it.


Line 14 of my C# code was commented out. I left it there
as a test to verify that the Extended Properties exist in
SQL Server, and to show you that I already know how to do
that.

Line 17 is not commented because that is the kind of
query I expect to run. I just want to query the DB,
and if any extended properties exist on the table
or column, I want them returned along with the result set.


I think you do not understand what I am asking. Is it
possible for you to get input from another MS engineer
or MVP?


Thanks.





_______ original message _______



I have created a table in MSSQL2K and added an Extended Property to
it.
I want the Extended Property to show up in the result DataSet. What
should I change to make this happen?

TSQL:


Create Table dbo.ZTestTable (
"ZTestTable_Id" int not null, "Col-1" varchar(184) null,
"Col-2" varchar(238) null
)
Go

Exec sp_addextendedproperty
'TableType', 'A test table.', 'user', dbo, 'table', [ZTestTable]
Go

Exec sp_addextendedproperty
'ColumnComment', 'ZTestTable primary key identifier.', 'user', dbo,
'table', [ZTestTable], 'column', [ZTestTable_Id]
Go

grant select on ZTestTable to public

Go



C#:

using System;
using System.Data;
using System.Data.OleDb;


class ExtenTest
{
[STAThread]
static void Main(string[] args)
{
DataSet outSet = new DataSet( "OutSet" );
string connString = "DATABASE=.........."

// string selectIt = "Select * From ::fn_listextendedproperty " +
"('TableType', 'user', 'dbo', 'table','ZTestTable',
null, null)";
string selectIt = "select * from ZTestTable";

OleDbConnection dbCn = new OleDbConnection( connString );
dbCn.Open();

OleDbDataAdapter dbAda = new OleDbDataAdapter( selectIt , dbCn
);
dbAda.Fill( outSet );
outSet.WriteXml( @"c:\extentest.xml" ,
XmlWriteMode.WriteSchema );

}
}



Thanks.
 
Thanks for the response. OK, so now I know I have to do a 2-step
process. I was afraid that was the case, but I wanted to know from
anyone with more experience (or MS knowledge) if it was possible to
get them all at once.

The Extended Properties in the DB contain info about each column that
can be used as contextual text in the GUI. So I need that info
stuffed into the ExtendedProperties collection at the DataColumn level
so it can be displayed on a form.

Thanks.
 
Did you read my article on Extended Properties?
http://www.betav.com/sql_server_magazine.htm
It might help clear up some issues.


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
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.
__________________________________
 
Yes, I did see that. I am comfortable with putting things in/out of
Extended Properties, I just wanted them to get into ExtendedProperties
after that. :)

Thanks.
 
IMO this is not automatic for now. It could be quite expensive to return
this all the time.

I would have the data layer filling ExtendProperties from an explicit query
for those properties. You may want also to "cache" those data avoid querying
them each time.

Hope it helps.

Patrice

--
 
I agree with Patrice. We cannot retrieve the extened properties from a Fill
method. In ADO.NET when we populate a dataset from a database table, only
data and PK info are retrieved from the server, it doesn't retrieve
extended properties from the server. The only workaround is to call stored
proc FN_LISTEXTENDEDPROPERTY from within .NET to get this info.

Luke
 
Hello,

Did you still have any concerns on this issue? If so, please feel free to
let me know.

Luke
 
Back
Top