Skip to main content

Posts

XQuery - Projecting Attributes With a Where Clause a Query

Had to write an xquery yesterday to extract some attribute values from an xml column, so I thought of posting it here for future reference. This the structure of my XML data stored in the column xmlColumn This is the records that I have in my table What I need is to select the Id column from a normal table column and then the "value" attributes from the xml coulumn whose "SiteText" is equal to 1 This is the query written in 2 different ways select id, xmlColumn. query('data(AuditRecord/Records/Record[@SiteText=1]/@value)') from temp select id, xmlColumn. value('data(AuditRecord/Records/Record[@SiteText=1]/@value)[1]', 'varchar(50)') from temp and this is the result set I get

Validating XML with an XSD using LINQ

So how do you validate an XML document that you get with a particular XSD?. One way you can do is with LINQ to XML with these steps. 1) Create a XmlSchemaSet 2) Add the schemas that your document needs to confirm to 3) Call the validate method of the XDocument So here is the example code. //Load an xml document XDocument doc = XDocument.Load(@"C:\test.xml"); //Define the schema set XmlSchemaSet set = new XmlSchemaSet(); //Add the schema to the set set.Add(string.Empty, @"C:\test.xsd"); //A variable to test whether our document is valid bool isValid = true; //Cal the validate method //Note that I am using a lambda function , alternativley you can use //pass in a delegate method as in the traditional method :) doc.Validate(set, (o, e) => { isValid = false; }); //Print out the result Console...

Exposing Enum Types From WCF

There are many cases where you would want to expose enum types from a WCF service, so how do you do this? Simply create a data contract and mark the values with the EnumMember attribute and thats it [DataContract] public enum MyEnumName { [EnumMember] CSV, [EnumMember] XML = 2 }

The maximum nametable character count quota (16384) has been exceeded

Some of our services were growing and the other day it hit the quote, I could not update the service references, nor was I able to run the WCFTest client. An error is diplayed saying " The maximum nametable character count quota (16384) has been exceeded " The problem was with the mex endpoint, where the XML that was sent was too much for the client to handle, this can be fixed by do the following. Just paste the lines below within the configuration section of the devenve.exe.config and the svcutil.exe.config files found at the locations C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE , C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin Restart IIS and you are done. The detailed error that you get is the following : Error: Cannot obtain Metadata from net.tcp://localhost:8731/ Services/SecurityManager/mex If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. F...

Configuring mexConnections with net.tcp binding

This is one of the issues that does not explain it self to me and I could not find any help from MSDN, so I thought of sharing in the blog for future use. I have a WCF library that is hosted in IIS, after some time we wanted to increase the max connection property of the service to 100 from the default value of 10 and also change the listenBackLog value to the same (if you dont know what these attributes do, a googling would help :0) The service was configured with 2 endpoints, a net;tcp endpoint and the the other being the meta data exchange endpoint using mexTcpBinding. I also configured a base address, part of the configuration file looks like this : Host it in IIS 7 and the service does not start at all and throws up an error like this : There is no compatible TransportManager found for URI 'net.tcp://ct-svr:8731/AuthorisationManager/Services.Security.AuthorisationManage...

Response.Redirect vs PostBackUrl

I normally use Response.Redirect to navigate from page to page, someone told me the other day that it would be better to use PostBackUrl of a control to redirect to a page then use Response.Redirect. So, I ran a little test of my own, created a 2 sample pages, where on a button click I do a Response.Redirect like this. protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("Advance.aspx"); } Next I ran Fiddler, this is the result I got on the button click, the response I get back from the server is not the content of the page I want but this... HTTP/1.1 302 Found Server: ASP.NET Development Server/10.0.0.0 Date: Mon, 10 May 2010 16:17:57 GMT X-AspNet-Version: 4.0.30319 Location: /Advance.aspx Cache-Control: private Content-Type: text/html; charset=utf-8 Content-Length: 130 Connection: Close Object moved to here . Here; point to the page you want to navigate to (have to live with this HTML formating :)) The server issues a 302 and the browser issues anot...

Passing in parameters into OPENQUERY

I was struggling for some time now, trying to pass in parameters into OPENQUERY, OPENQUERY does not support passing in parameters, all it does it takes a string value as the 2nd parameter like this, SELECT * FROM OPENQUERY(LINKSERVER_NAME, 'SELECT * FROM COUNTRY WHERE COUNTRYID = 10') What's worse, it does not support passing in a varchar variable as the 2nd parameter. So, if you want to pass in parameters, then one of your option is creating a dynamic query and executing it like this declare @var int = 10 declare @query varchar(max) = 'select * from openquery(Test_link,' + '''' + 'SELECT * FROM dbo.TEMP where ID > ' + CAST(@var AS VARCHAR(MAX)) + '''' + ')' execute(@query) IF you want to use the result returned by OPENQUERY, like for an example for joining to another source table, you would have to create a table variable, populate your result and start joining, and illustration would be like this (hypothetical...