473,416 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Cannot file relation 0

I have found what appears to be an error in streaming with Datasets. It
causes an error of 'Cannot find relation 0' when recreating the dataset from
a stream.

Here is how you reproduce it.

Lets assume you have tables like this:
Customers
CustomerName: Varchar(50)
CustomerNumber: Int (Primary Key)
Addresses:
CustomerID: Int (Foreign Key)
Street: varchar(40)

Using the dataset designer and a database with a master-detail relationship
on it:
Drop the 'Master' table (Customers) and 'detail' table (Addresses) and
create the relationship between the CustomerID field between them using drag
and drop in the dataset designer.

Now, add a field to the detail dataset (Addresses) and call it
'CustomerName'. Set the expression of this new field to
'Parent.CustomerName'.

Now using whatever means necessary, load the dataset with data.

Everything will work as expected - no problems.

Using ASP.NET assign the dataset above to the session (causing it to be
streamed):
HttpContext.Current.Session["test"]=dset;

Now load it from the stream:
Mydatasettype dset=(Mydatasettype)Session["test"];

You will get the error when it streams back. If you remove the expression
of 'Parent.CustomerName' from the dataset definition the error will go
away...

Can I please get help/fix/etc?

Wayne

Here is the complete error info...



Source Error:

Line 74: this.CaseSensitive = ds.CaseSensitive;
Line 75: this.EnforceConstraints = ds.EnforceConstraints;
Line 76: this.Merge(ds, false,
System.Data.MissingSchemaAction.Add);
Line 77: this.InitVars();
Line 78: }

Source File: loginandrights.cs Line: 76

Stack Trace:

[IndexOutOfRangeException: Cannot find relation 0.]
System.Data.DataTableRelationCollection.get_Item(I nt32 index)
System.Data.LookupNode.Bind(DataTable table, ArrayList list)
System.Data.DataExpression.Bind(DataTable table)
System.Data.DataExpression..ctor(String expression, DataTable table, Type
type)
System.Data.DataColumn.set_Expression(String value)
System.Data.Merger.MergeSchema(DataTable table)
System.Data.Merger.MergeTableData(DataTable src)
System.Data.Merger.MergeDataSet(DataSet source)
System.Data.DataSet.Merge(DataSet dataSet, Boolean preserveChanges,
MissingSchemaAction missingSchemaAction)
LoginAndRights..ctor(SerializationInfo info, StreamingContext context) in
loginandrights.cs:76

[TargetInvocationException: Exception has been thrown by the target of an
invocation.]
System.Reflection.RuntimeConstructorInfo.Serializa tionInvoke(Object
target, SerializationInfo info, StreamingContext context) +0
System.Runtime.Serialization.ObjectManager.Complet eISerializableObject(Object
obj, SerializationInfo info, StreamingContext context) +149
System.Runtime.Serialization.ObjectManager.FixupSp ecialObject(ObjectHolder
holder) +128
System.Runtime.Serialization.ObjectManager.DoFixup s() +170
System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(HeaderHandler
handler, __BinaryParser serParser, Boolean fCheck, IMethodCallMessage
methodCallMessage) +269
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler, Boolean fCheck,
IMethodCallMessage methodCallMessage) +183
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(Stream
serializationStream) +11
System.Web.Util.AltSerialization.ReadValueFromStre am(BinaryReader reader)
System.Web.SessionState.SessionDictionary.Deserial ize(BinaryReader
reader)
System.Web.SessionState.StateClientManager.Deseria lize(Stream stream,
Int32 lockCookie)
System.Web.SessionState.SqlStateClientManager.DoGe t(String id, SqlCommand
cmd)
System.Web.SessionState.SqlStateClientManager.GetE xclusive(String id)
System.Web.SessionState.StateClientManager.BeginGe tExclusiveSync(String
id, AsyncCallback cb, Object state)
System.Web.SessionState.SqlStateClientManager.Syst em.Web.SessionState.IStateClientManager.BeginGetEx clusive(String
id, AsyncCallback cb, Object state)
System.Web.SessionState.SessionStateModule.GetSess ionStateItem()
System.Web.SessionState.SessionStateModule.BeginAc quireState(Object
source, EventArgs e, AsyncCallback cb, Object extraData)
System.Web.AsyncEventExecutionStep.System.Web.Http Application+IExecutionStep.Execute()
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean&
completedSynchronously)

Nov 18 '05 #1
7 3811
Hi Wayne,

Thanks for your posting. As for the problem you described, I've done a
simple local test with the following table

Customers
Customers
CustomerID: Int (Primary Key) (auto increase)
CustomerName: Varchar(50)

Addresses:
CustomerID: Int (Foreign Key)
Street: varchar(50)

And I generate a TypedDataSet via draging the two sql tables and also add a
customer property in the

Addresses DataTable which get the parent record's CustomName via :
public string CustomerName
{
get
{
return this.CustomersRow.CustomerName;
}
}

When testing in asp.net page, I can store the TypedDataSet into Session and
retreive back from session correctly. So I'm thinking there maybe some
thing else cause the issue. I've attached my test DataSet and page in this
message, you can test it on your side.

In addition, you can also have a try to see whether the problem also occur
if you didn't add the custom property in Addresses Table, and from the
Error Message, it seems that when deserialize back form the session, the
TypedDataSet fail to retrieve back the Relation. So you can also test to
see whether any relations you add in your typeddataset will fail to be
serialized into session.
Also, what's the sessionState Mode you're using in your asp.net
application, InProc or StateServer or SqlSession?

Please have a check and if there's any further finding, please feel free to
post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Nov 18 '05 #2
Steven,
Thanks for your post.

Couple of things:
1) When you add a custom element to the dataset diagram, set its type
to string and set the 'Expression' property of that field to
'Parent.CustomerName'.
After you do this, the MSDataSetGenerator will generate a class
for you - it is that class we are going to stream. I have no idea what or
how you did this:
Addresses DataTable which get the parent record's CustomName via :
public string CustomerName
{
get
{
return this.CustomersRow.CustomerName;
}
}
2) You do not mention if you dragged the CustomerID field from
Customers to the CompanyID field in Addresses. This creates the relation.
If you did, great, if not then I need you to do this part.
3) I am using SQL for session state.
4) There were no attachments to this message.

Having said all of that, I located the problem and modified the source
generated from MSDataSetGenerator so that it WILL stream correctly. The
root of the problem is as the columns are read in, it reads in the
expression for the column - however, at the time it does that, the relations
are not established causing an error. The reason it works when you create
the class with a call to new myTypedDataset is the column expression is not
assigned until after everything is created.

Here is the modification:

There is a method signature (constructor) of:
protected TypeDataSetClassName(SerializationInfo info, StreamingContext
context) {

In the first IF block you will add a line after InitVars (last line in the
if block) as follows:
this.InitExpressions(); //WB

That causes the Expressions for columns to be initialized AFTER everything
is setup. The method InitExpressions() was created by the
MSDataSetGenerator, but will NOT be there unless you have an expression in a
column.

The other change is to REMOVE the expression from the column!!! In the
constructor of the class for the table with the Expression (in this case
Addresses) you will find a constructor that takes a DataTable as an
argument:

internal AddressesDataTable(DataTable table) :

At the bottom of the method, add this:

table.Columns["CustomerName"].Expression=""; //WB
So, the way this works again is this:
When constructed from code, the expression is assigned in the
InitExpressions() function, so the fact that we blanked out the Expression
has no effect. However, when read from a completed dataset that was
streamed out - this Expression is populated and will cause an error - so
when this class is constructed, we blank it out. After everything has been
constructed in the dataset, we set the expression back by calling
InitExpressions() [that is the first part of the modification]

------------------------------------------------------------------------------------------------

BTW, in messing with this, I found a problem with a method. The Copy method
of a dataset...(once the get the above example basics working you can use it
to try this).
//Show it works with original....

MyTypedDataSet dset=ExistingDataSet;

if (dset==null){

return;

}

dset.CustomerNameColumn.Expression="Parent.Custome rName";

//now use CopyOfDset and reference the CustomerName field. It will work as
expected...
//Try to copy the entire dataset

MyTypedDataSet dset=ExistingDataSet;

if (dset==null){

return;

}

MyTypedDataSet CopyOfDset=dset.Copy();

CopyOfDset.CustomerNameColumn.Expression="Parent.C ustomerName";

//now use CopyOfDset and reference the CustomerName field. It will always be
blank.


"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:5n**************@cpmsftngxa10.phx.gbl... Hi Wayne,

Thanks for your posting. As for the problem you described, I've done a
simple local test with the following table

Customers
Customers
CustomerID: Int (Primary Key) (auto increase)
CustomerName: Varchar(50)

Addresses:
CustomerID: Int (Foreign Key)
Street: varchar(50)

And I generate a TypedDataSet via draging the two sql tables and also add
a
customer property in the

Addresses DataTable which get the parent record's CustomName via :
public string CustomerName
{
get
{
return this.CustomersRow.CustomerName;
}
}

When testing in asp.net page, I can store the TypedDataSet into Session
and
retreive back from session correctly. So I'm thinking there maybe some
thing else cause the issue. I've attached my test DataSet and page in this
message, you can test it on your side.

In addition, you can also have a try to see whether the problem also occur
if you didn't add the custom property in Addresses Table, and from the
Error Message, it seems that when deserialize back form the session, the
TypedDataSet fail to retrieve back the Relation. So you can also test to
see whether any relations you add in your typeddataset will fail to be
serialized into session.
Also, what's the sessionState Mode you're using in your asp.net
application, InProc or StateServer or SqlSession?

Please have a check and if there's any further finding, please feel free
to
post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
HI Wayne,

Thanks for your response. I've read the modified TypedDataSet and seen the
things you mentioned. I'm sorry for my mistakes that I didn't add a new
Element in the AddressTAble's schema (which has a expression). I just
manually add a public property named "CustomerName" in the AddressesRow
class in the dataset's .cs source file. After test your code, I've found
the problem you mentioned, yes, as you said, that's because the dataset's
constructing order when it is deserialized from Session. And it is also
because the Session Mode is SqlSErver mode so that the

OrderDS(SerializationInfo info, StreamingContext context)

constructor will be called. I used to use InProc Session mode so that
haven't found the problem.

In addition, since the problem is caused by the DataRelation hasn't been
created before the TypedDataSet Merge data from the Session deserialized
data, we can also workaround it via only modifying the

OrderDS(SerializationInfo info, StreamingContext context)

constructor as below:

=====================
protected OrderDS(SerializationInfo info, StreamingContext context) {

// always call the InitClass here so as to reconstruct the TypeDS's
structure
this.InitClass();

string strSchema = temp = ((string)(info.GetValue("XmlSchema",
typeof(string))));

if ((strSchema != null))
{
DataSet ds = new DataSet();
ds.ReadXmlSchema(new XmlTextReader(new
System.IO.StringReader(strSchema)));

// since the two tables have been added into the Tables
collectoin in "InitClass", we don't
// need to readd them
// change to use if ((ds.Tables["Addresses"] != null &&
this.tableAddresses == null))

if ((ds.Tables["Addresses"] != null && this.tableAddresses
== null)) {
this.Tables.Add(new
AddressesDataTable(ds.Tables["Addresses"]));
}
if ((ds.Tables["Customers"] != null && this.tableCustomers
== null)) {
this.Tables.Add(new
CustomersDataTable(ds.Tables["Customers"]));
}

==========================================

Thus, we don't need to change other places in the DataSet's code file.

I've also checked some former issues dicussing on the similiar problem when
deserializing the TypedDataSet. Currently it seems that we can only
manually do some modification on the ds's generated source code to overcome
the problem. If you still have any questions on this, please feel free to
post here. Also, I'm sorry for the inconvenience it has brought you.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #4
Steven,
I think it is NOT an acceptable workaround to change the code everytime
your dataset changes.

1) Did you submit this as a bug so the team will correct it?
2) Is it possible to get an updated MSDataSetGenerator tool?

Do I have any other alternatives?


"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:1p**************@cpmsftngxa10.phx.gbl...
HI Wayne,

Thanks for your response. I've read the modified TypedDataSet and seen the
things you mentioned. I'm sorry for my mistakes that I didn't add a new
Element in the AddressTAble's schema (which has a expression). I just
manually add a public property named "CustomerName" in the AddressesRow
class in the dataset's .cs source file. After test your code, I've found
the problem you mentioned, yes, as you said, that's because the dataset's
constructing order when it is deserialized from Session. And it is also
because the Session Mode is SqlSErver mode so that the

OrderDS(SerializationInfo info, StreamingContext context)

constructor will be called. I used to use InProc Session mode so that
haven't found the problem.

In addition, since the problem is caused by the DataRelation hasn't been
created before the TypedDataSet Merge data from the Session deserialized
data, we can also workaround it via only modifying the

OrderDS(SerializationInfo info, StreamingContext context)

constructor as below:

=====================
protected OrderDS(SerializationInfo info, StreamingContext context) {

// always call the InitClass here so as to reconstruct the TypeDS's
structure
this.InitClass();

string strSchema = temp = ((string)(info.GetValue("XmlSchema",
typeof(string))));

if ((strSchema != null))
{
DataSet ds = new DataSet();
ds.ReadXmlSchema(new XmlTextReader(new
System.IO.StringReader(strSchema)));

// since the two tables have been added into the Tables
collectoin in "InitClass", we don't
// need to readd them
// change to use if ((ds.Tables["Addresses"] != null &&
this.tableAddresses == null))

if ((ds.Tables["Addresses"] != null && this.tableAddresses
== null)) {
this.Tables.Add(new
AddressesDataTable(ds.Tables["Addresses"]));
}
if ((ds.Tables["Customers"] != null && this.tableCustomers
== null)) {
this.Tables.Add(new
CustomersDataTable(ds.Tables["Customers"]));
}

==========================================

Thus, we don't need to change other places in the DataSet's code file.

I've also checked some former issues dicussing on the similiar problem
when
deserializing the TypedDataSet. Currently it seems that we can only
manually do some modification on the ds's generated source code to
overcome
the problem. If you still have any questions on this, please feel free to
post here. Also, I'm sorry for the inconvenience it has brought you.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5
Hi Wayne,

Thanks for the followup. Yes, I've contacted the dev team and they've
already filed this issue in the existing known issue lists for the
currently version of ADO.NET. Also, currently it seems that we could only
manually do some modification in the code file to workaround it. In fact,
the problem is concerned with any columns which has a Expression in a
TypedDataSet , such column will cause the Merge of the Dataset(when
deserialize from persistence stream).
This issue is going to be fixed in the next version of ADO.NET ( Whidbey
version of .net ). Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #6
Does microsoft realize what a pain this is? All they have to do is ship the
SOURCE to that one tool. Or publish a fix to that one tool. Empower
developers to help themselves. Imagine the mods that would have already
been created on this MSDataSetGenerator class for enhanced functionality.

Please pass my suggestion along. www.adoguy.com made one for his book - I
am going to look into using it -as it comes with source (my gosh this is not
a super secret you need to protect). I guess I could disassemble it and
try to repair it...
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:Pk****************@cpmsftngxa10.phx.gbl...
Hi Wayne,

Thanks for the followup. Yes, I've contacted the dev team and they've
already filed this issue in the existing known issue lists for the
currently version of ADO.NET. Also, currently it seems that we could only
manually do some modification in the code file to workaround it. In fact,
the problem is concerned with any columns which has a Expression in a
TypedDataSet , such column will cause the Merge of the Dataset(when
deserialize from persistence stream).
This issue is going to be fixed in the next version of ADO.NET ( Whidbey
version of .net ). Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #7
Hi Wayne,

Thanks for your sincere advice. Yes, I agree with you that it's a good idea
that the .NET involve all the communitry , developers to enhance it. And
actually most of the new features or updates in the new verions of .net are
contributed by the feedbacks from our customers.

In addition, I also recommend that you forward the recommendation to the
Microsoft Wish Program:

Microsoft offers several ways for you to send comments or suggestions about
Microsoft products.
World Wide Web - To send a comment or suggestion via the Web, use one of
the following methods:

" In Internet Explorer 6, click Send Feedback on the Help menu and then
click the link in the Product Suggestion section of the page that appears.
" In Windows XP, click Help and Support on the Start menu. Click Send your
feedback to Microsoft, and then fill out the Product Suggestion page that
appears.
" Visit the following Microsoft Web site: http://www.microsoft.com/ms.htm
" Click Microsoft.com Guide in the upper-right corner of the page and then
click Contact Us . Click the link in the Product Suggestion section of the
page that appears.
" Visit the following Microsoft Product Feedback Web site:
"http://register.microsoft.com/mswish/suggestion.asp" and then complete and
submit the form.

Thanks again for your understanding.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: mir nazim | last post by:
hi. i want to know if there is any flat-file relational database system available for python. i require it in a project. it should have following capabilities: 1. should be small and compact on...
3
by: MSSQLServerDeveloper | last post by:
I have a simple vb.net program that creates an xmlschema using the dataset method writexmlschema (see #1). It creates a file (see #2), but I would like a file that looks like #3 - #3 is DIFFERENT...
3
by: Krish | last post by:
I have created 2 tables, both tables have the same column names (property ColumnName) it is priceDate,priceTime and priceValue I get an error saying that Column priceDate already belongs to...
3
by: Fabio Negri Cicotti [MCP] | last post by:
Hi All. I'm trying to insert data into 2 tables (parent-child) using the ADO.NET's SetParentRow method. The parent table has an identity column as primary key. When I execute the code below I...
1
by: bitwxtadpl | last post by:
-First I add and relate the tables A and B. Create a new instance of TableA Add TableA to DataSetX Create a new instance of TableB Add TableB to DataSetX Create a relation between TableA and...
1
by: Random | last post by:
I don't understand why this error is happening when I try to load my xml into my DataSet. "Cannot add a nested relation or an element column to a table containing a SimpleContent column." Can...
4
by: Devrim GUNDUZ | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I've just upgraded a production database from 7.3.4 to 7.4.2. I 'sometimes' get the following error while executing a PHP code:
1
by: Hennesey | last post by:
Hello all, I am developing a Visual Studio .Net 2005 application that consumes an Axis 1.3 web service. Importing the WSDL file generates an error "cannot resolve apachesoap:Map type" ...
3
by: Eric | last post by:
Help! I created a XML schema with a Visual Studio tools. I'm filling a dataset with a DataAdapter. Before I use the "WriteXml" method to write the data to a xml file, I want to map the XSD file I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.