tag:blogger.com,1999:blog-41516546475227541992024-02-19T23:28:26.136-08:00Suthin RavinsAnything about anything that comes to my mind.
<br>
<a href="http://www.bloglovin.com/blog/4083701/?claim=b634rcf5pga">Follow my blog with Bloglovin</a>Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.comBlogger47125tag:blogger.com,1999:blog-4151654647522754199.post-53068248305624922842019-03-03T17:01:00.001-08:002019-03-03T17:01:57.489-08:00To Paraphrase James Brady, "Killer Trees!"Most people get their home inspected when they look to purchase one. You want to make sure your new home isn't full of hazards and potential money pits. You'll seek to have all the major systems checked out: electrical, plumbing, gas connections, the roof, the crawl space, the attic, the siding, windows, floors, appliances when they'll convey and slabs when any evidence presents itself that there might be issues under them. You'll pay attention to dated elements, room flow, open concept versus the kitchen being dark or isolated. You might pay attention to the driveway and other paved areas, although I'm sure for many that is more likely to be an overlooked afterthought. Your inspector will almost certainly bring up issues with any decking and even point out drainage issues in your yards. Chimneys will get enough attention for the average inspector to recommend you get a certified chimney professional out to give it a better look. You might even pay attention to the strength of your mobile phone signal and the proximity, for better or worse depending on your perspective, of the nearest cell towers. You may also pay attention if those monstrous high tension overhead power lines run close by. You'll likely want to know if the property is in a flood zone. You'll definitely make sure a termite inspection has been done and might even test for radon.
There's one element however that I'll bet few of you pay any attention to.
THE TREES!
We're now in our second house and for both homes combined, EVEN counting a paid roof replacement (We didn't luck out with a hail storm to get it for free), the single biggest source of expense for us has been, you've now guessed it, our arboreal work.
Trees are a maintenance nightmare, especially when they're old, tall and sickly. The worst, at least by us, are the gangly loblolly pines and cedars.
Every couple of years we find ourselves pouring 4 figures down the storm drain to get trees pruned and removed.
A tree that's fine this year, may be in distress two years later.
A tree that was already kind of iffy two years earlier is suddenly an overnight nightmare that has to come down right away.
And everything else in the house has to take a back seat to them. They cannot be ignored. You dare not ignore them. Substantial limbs will not just hurt, but kill whoever they fall on.
Just a big limb, let alone the whole tree can come crashing through a roof, crush a car and worse.
You have to have your trees inspected regularly, no different than your AC system or termite inspections.
So word to the wise, add a good arborist to your pre-purchase home inspection team.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-79214054486781917892019-03-03T16:24:00.000-08:002019-03-03T16:25:19.182-08:00The Last Frontier for Free Phone Number SearchingI stumbled upon what may be the last great white (pages) hope, the last source for finding someone's phone number without having to pay.<br />
<a href="https://www.usphonebook.com" title="US Phone Book">US PhoneBook</a>Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-16111413802681910132018-09-01T10:15:00.002-07:002018-09-01T10:15:49.940-07:00Worked Over by MySql Workbench?Just went through angina after installing the latest version of MySql Workbench 8.0. Kept getting bad handshake errors connecting to a remote MySql database. Turns out that data base still runs on an antiquated version of MySql 5 and Workbench 8 is a typical liberal nanny state interface program that doesn't like conservative older database servers and feels it knows better than everyone else and that anyone who wants the benefits of its use better provide newer databases to use with it.
Welllllll, upgrading that particular database just isn't in the cards this minute. Connecting remotely with it is.
End shot bottom line, went back to Workbench 6.3.10 and SCREW Workbench 8.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-90042272027489528792018-08-26T19:47:00.001-07:002018-08-26T19:51:06.203-07:00OhMySQL! Ya gonna Be the Death of Me!Finally returned to my hobby website, <a href="http://www.streetlightsite.com">www.StreetlightSite.com</a>, after like years of neglect. That site is totally driven by data stored on a MySQL database server and my extremely budget hosting plan hasn't had an update done to that server since around when I last updated any data on it. Suffice to say when I renewed my own localhost virtual server to do update development work on, I needed to start downloading regular database back ups again.
Well, I'd been so out of it with MySQL I kind of forgot what I needed to do. Thought it would be as easy as exporting the whole shebang from one and importing into the other.
WRONG!<br />
Kept getting the wonderful MySQL error 1024 syntax error where TYPE=InnoDB. Well, I was just about to stick a TYPE up MySQL's InnoDB when I thankfully discovered that my virtual server's MySQL 5.6 is virulently WORDIST! It is prejudiced against the word TYPE. Only native born, full blooded ENGINEs are allowed.
Bottom line? Just replaced TYPE= with ENGINE= and order was restored to the universe.<br />
<a href="https://twitter.com/StreetlightSite">Follow @StreetlightSite on Twitter</a>Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-2915099285664834262017-05-11T21:40:00.000-07:002017-05-11T21:40:02.611-07:00Don't Cast Numerics to Varchars In SQL JoinsHad a performance issue with a stored procedure recently and discovered why the thing was choking, taking minutes to run.
It had a most unfortunate join factor among the several joins in a complex query.
The join was a varchar field matched to an integer field.
For whatever reason long lost in time, the writer decided to cast the integer as a varchar to map it against the crazy varchar field, whose values could be anything from numbers to symbols.
That field's data content was out of our control, coming from an outside source and possibly needing to be preserved as is for auditing.
The only values in that field however that meant anything to us were the numeric ones.
What fixed the ridiculous runtime of this proc was to reverse the casting.
I changed the join to instead cast the varchar as an int to match against the real int.
To do that I had to make sure the varchar was numeric inside the cast.
join dbo.StupidTableWithIdioticVarcharField s on cast(case when isnumeric(s.StupidField) = 1 then s.StupidField else 0 end as int) = NormalTable.NormalIntField
The speedup was breathtaking. It would've been more breathtaking if the original data was designed, or at least redesigned differently, but sometimes you just gotta work with what you got.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-28998762547922796042017-05-11T21:28:00.001-07:002017-05-11T21:28:23.166-07:00Naming Temp Tables in Stored Procedures called by OthersBeware the temp table names you use when naming such tables in a stored procedure that in turn gets executed inside other stored procedures.
If both the executing and executed procedures have temp tables with the same name, you might be in for a nightmarish episode of tearing your hair roots out.
If using the same #TableName in both procedures, they must have the same exact column structure.
You later add a column to the executor and don't do the same to the executed, you will end up tempted to execute yourself before you figure out why you keep getting insert errors in the child proc.
Bottom line, keep temp table names different in procs called by other procs.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-7061223213677629092015-09-19T12:38:00.001-07:002015-09-19T12:41:38.347-07:00Very happy with reconditioned Dewalt drill set from CPO<span style="color: #999999; font-family: monospace; font-size: 9.88px;"></span><br />
<div class="hreview">
<div class="item">
<span style="color: #999999; font-family: monospace; font-size: 9.88px;"><a href="http://www.cpopowertools.com/factory-reconditioned-dewalt-dcd980m2r-20v-max-cordless-lithium-ion-1-2-in--premium-3-speed-drill-driver-kit-with-4-0-ah-batteries/dewrdcd980m2r,default,pd.html">Originally submitted at CPO Dewalt</a></span><br />
<div>
<span style="color: #999999; font-family: monospace; font-size: 9.88px;"><img align="left" class="photo" src="http://images.powerreviews.com/images_products/03/90/34136878_100.jpg" style="margin: 0 0.5em 0 0;" /></span><br />
<div style="margin-top: 0;">
<span style="color: #999999; font-family: monospace; font-size: 9.88px;">20V MAX Cordless Lithium-Ion Premium 3-Speed Drill Driver - DCD980M2R. (2) 20V MAX 4.0 Ah Lithium-Ion Batteries. Charger. Side Handle. Carrying Case</span></div>
</div>
<span style="color: #999999; font-family: monospace; font-size: 9.88px;"><a class="url fn" href="http://www.cpopowertools.com/factory-reconditioned-dewalt-dcd980m2r-20v-max-cordless-lithium-ion-1-2-in--premium-3-speed-drill-driver-kit-with-4-0-ah-batteries/dewrdcd980m2r,default,pd.html" style="display: none;"><span class="fn">20V MAX Cordless Lithium-Ion 1/2 in. Premium 3-Speed Drill Driver Kit with 4.0 Ah Batteries</span></a></span></div>
<span style="color: #999999; font-family: monospace; font-size: 9.88px;"><br clear="left" /></span>
<span style="color: #999999; font-family: monospace; font-size: 9.88px;"><strong class="summary">Very happy & surprised. Didn't expect new XR batteries</strong></span><br />
<div>
<span style="color: #999999; font-family: monospace; font-size: 9.88px;">By <strong>Jeff</strong> from <strong>Charlotte</strong> on <strong><abbr class="dtreviewed" style="border: none; text-decoration: none;" title="2015919T1200-0800">9/19/2015</abbr></strong></span></div>
<span style="color: #999999; font-family: monospace; font-size: 9.88px;"><br /></span>
<div style="display: none;">
<span style="color: #999999; font-family: monospace; font-size: 9.88px;"><span class="rating">5</span>out of 5</span></div>
<span style="color: #999999; font-family: monospace; font-size: 9.88px;"><strong>Pros: </strong>Powerful, Easy To Use, Good Battery Power</span><br />
<div class="description" style="margin-top: 1em;">
<span style="color: #999999; font-family: monospace; font-size: 9.88px;">Bought kit basically for the 4ah batteries and charger to use with my Dewalt saws. The drill was like a freebie for the price and is a great drill, more powerful that the other one we own and that stabilizer handle came in handy very fast as I drilled into tree roots I'm trying to destroy. I didn't expect to get the new XR batteries with this and that made me very happy! They shipped very fast too. I'm usually loath to order refurbished items, but this one turned out great!</span></div>
<div style="margin-top: 0.5em;">
<span style="color: #999999; font-family: monospace; font-size: 9.88px;">(<a href="http://www.powerreviews.com/legal/terms_of_use.html" rel="license">legalese</a>)</span></div>
</div>
<span style="color: #999999; font-family: monospace; font-size: 9.88px;">
</span>Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com1tag:blogger.com,1999:blog-4151654647522754199.post-77816609189072818542015-01-23T09:52:00.003-08:002015-01-23T09:52:51.373-08:00Selecting Recordset from SQL Server with Same Name Columns<span style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;">This applies to SQL Server 2008 R2 and VB.Net.</span><br />
<span style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;">Thought I'd share what I discovered inside a VB.Net project converted from old VB6 code. We have a recordset that used to be brought in from SQL Server 2008 R2 via ADODB that had 2 fields from different tables with same name.</span><br style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;" /><span style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;">The old VB6 project apparently ignored the one from the first table and used the second, as the program was designed to do.</span><br style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;" /><span style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;">I wasn't aware of this right away. Following the .Net conversion I changed this database call to use System.Data.SqlClient.SQlCommand, replacing the original recordset with a datatable fill.</span><br style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;" /><span style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;">Suddenly, I wasn't getting the value I expected when this field was read for each row.</span><br style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;" /><span style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;">After going back and seeing what the stored procedure was set up to do (SIGH!!!) I learned that the insert into my datatable appended a "1" to the name of the second of the same-named fields.</span><br style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;" /><span style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;">The first SAMEFIELDNAME was left as is, the second became SAMEFIELDNAME1.</span><br style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;" /><span style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;">Not able for various reasons to alias the column names in the proc, which needed to remain as is for other users, I just recoded the program to read field SAMEFIELDNAME1.</span><br />
<span style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;"><br /></span>
<span style="background-color: #fafafa; color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;">I also posted this on VB Forum at:</span><br />
<span style="background-color: #fafafa; font-size: 13px;"><span style="color: #333333; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif;">http://www.vbforums.com/showthread.php?627485-How-to-distinguish-between-2-fields-with-the-same-name-(after-a-table-join)-in-vb6</span></span>Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-18591110471461501682014-11-28T21:42:00.003-08:002014-11-28T21:47:58.653-08:00What Garmin, or Should I Call Them GRRRRRRRman Doesn't Tell YouWe have a Nuvi 40LM Garmin GPS that's supposed to have lifetime map replacement. Well, that ain't worth to much if you can't get their Garmin Express, or should I call it Garmin Exasperating, device syncing software to recognize your device.<br />
I tried plugging the GPS into 3 different PCs, with Windows 8.1, 7 and XP, using 3 different USB cables, including a brand new official Garmin cable out of desperation.<br />
I was always able to get both the device drive and MicroSD card inside of it recognized as drives in Windows Explorer, but the Garmin Express would never open up as it was supposed to, the moment we plugged the device in, nor would it ever find the device when we opened it manually.<br />
We tried everything, including older Garmin Map Updaters and the MyGarmin interface on their site.<br />
It wasn't until I wrote their customer service for help (Being they don't deign to offer after hours phone support).<br />
I was shocked to get an email back a few hours later and DAD GUM if they didn't actually give me workable advice, so since it worked for us, here it be for you.<br />
<span style="background-color: #7f6000;"><br /></span>
<div>
<span style="background-color: #7f6000;">Personally, I think you can get it to work just by removing that GarminDevice xml file in the Garmin folder. I'd try that first.</span></div>
<div>
<span style="background-color: #7f6000;">I also first backed up all the files I removed from the device folders. It was about 1.7GB.</span></div>
<div>
<span style="background-color: #7f6000;"><br /></span></div>
The following is quote/unquote verbatim from their email to me:<br />
<br />
<br />
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">When the device is connected to the computer what do you see on the screen of your device? If the device displays the Garmin logo with a picture of the device connected to the computer tower, you should be able to go into the nuvi drive and remove unnecessary files from the device. I have included these steps below. </span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">1. Connect your GPS to the computer and allow the computer time to find the device</span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">2. Open the Garmin drive, (PC: under "Computer" or "My Computer" Mac: On the Garmin Drive mounted on the desktop)</span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">3. Inside the Garmin drive you will find several folders, you will want to go into each and remove any files you will not be using.</span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;"> Help - Remove any language that you will not be using - You will want to keep American_English file</span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;"> Keyboards - Remove any keyboards other then keyboards you will be using as well as the EN_US file</span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;"> Text - Remove any text files that you will not be using, please keep any that begin with EN_GB</span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;"> Voice - Remove any voice files that you will not be using, please keep any American English Voices</span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;"> Garmin - inside of the Garmin Folder, delete the GarminDevice or GarminDevice.XML Folder</span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">4. Once the files have been removed, disconnect the GPS from the computer and allow it to power on.</span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">5. When the device is loaded to the main 'Where To/View Map" screen allow it to wait there for appx. 30 seconds </span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">6. After 30 seconds, reconnect the unit to the computer and Garmin Express should find the device. </span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<br /></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">If your device is not displaying the Garmin logo with the picture of the device connected to the computer tower, please connect the device to a different USB port on the computer. If you are using a desktop, please connect the device to the USB port on the back of the computer. If the device is still not connecting to the computer please check the cable to make sure it is the Garmin branded cable. If you look at the end that connects to the computer, below the USB plug the Garmin logo should be embossed on the casing below. If you do not see the Garmin logo on this cable, please try to use a different USB cable. Although these cables look similar and fit they can often transfer data differently. </span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">If you are still having trouble with your device connecting to the computer, please follow the steps below to perform a soft reset. </span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">1. Connect the device to the computer or vehicle power cable</span></div>
<div style="font-family: arial, sans-serif; font-size: 13px;">
<span style="background-color: #ffe599; color: #351c75;">2. Press and hold on the power button for 10-15 seconds</span></div>
<br />
<div style="font-family: arial, sans-serif; font-size: 13px;">
</div>
<br />
<div style="-webkit-text-stroke-width: 0px; color: black; font-family: arial, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px;">
<div style="margin: 0px;">
<span style="background-color: #ffe599; color: #351c75;">3. Release the power button and the device should power back on.</span></div>
</div>
<br />Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-22545446504399192442014-06-06T08:19:00.001-07:002014-06-06T08:22:46.239-07:00SSIS Overwriting Excel file destination and Fixing 64 bit Run IssueI had a problem getting an SSIS package to write correctly to an Excel destination.<br />
The first issue was that the Excel Connection Manager couldn't work in 64 bit mode, which my operating system and the SQL server running the package are.<br />
This required a little fix in both the dtsx package, and the SQL server agent job running it.<br />
<br />
The first step of fixing the dtsx package came from:<br />
<a href="http://merlecarr.wordpress.com/2011/02/12/the-excel-connection-manager-is-not-supported-in-the-64-bit-version-of-ssis/">http://merlecarr.wordpress.com/2011/02/12/the-excel-connection-manager-is-not-supported-in-the-64-bit-version-of-ssis/</a><br />
<br />
1: Open the project properties window (Not the package properties, but its parent project).<br />
2: Go to Debugging beneath Configuration Properties.<br />
3: Set Run64BitRuntime to False.<br />
<br />
Then in your Server Agent job's properties, open to edit the step(s) running any such package and:<br />
1: Open Advanced beneath the "Select a page" menu on the left.<br />
2: Choose the "Exectution options" tab.<br />
3: Check "Use 32 bit runtime".<br />
<br />
Now that this worked, the new problem was that by default, the Excel destination just gets appended to, not overwritten. If you need to always refresh the destination file data, you have to first run a task to wipe the slate clean before importing the new data.<br />
<br />
Ultimately this thread provided most of the answer:<br />
<a href="http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e26692b8-8044-4813-b643-0c181a1ea4fe/deleting-records-in-an-excel-sheet-using-ssis">http://social.msdn.microsoft.com/Forums/sqlserver/en-US/e26692b8-8044-4813-b643-0c181a1ea4fe/deleting-records-in-an-excel-sheet-using-ssis</a><br />
<br />
1: Create a blank template of your destination Excel file to preserve your column setup.<br />
2: Place a File System Task ahead of your Data Flow Task that imports the destination data.<br />
3: In that file system task, set Operation to "Copy File".<br />
4: Set your Destination Connection to the destination file, with OverwriteDestination set to True.<br />
4: Set Source Connection to your template file.<br />
<br />
That should be all it takes, but wouldn't it be amazing if MicroSoftInTheHead would update their @#$%^&* Jet Engine to provide a simple checkbox for overwriting existing data in the Excel Destination data flow? Yeah, right, like we'll ever see that in our lifetime.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com2tag:blogger.com,1999:blog-4151654647522754199.post-22548543893843944012014-05-22T11:53:00.002-07:002014-05-22T11:53:12.028-07:00C# class with Methods to Get Json or Xml Data Into ListBelow is a class of columns returned by a web service API, with methods to get that data in either Json or Xml form, and send that data into a List of the class properties.<br />
<br />
The controller ActionResult (Site is .Net MVC) using this class either uses:<br />
<br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace;">BusInfo bi = new Models.BusInfo();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace;"> IEnumerable<businfo> model = bi.getDataX();//gets data via xml from web service</businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace;"> ViewData["PageTitle"] = "Business Information";</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace;"> return View(model);</span><br />
<br />
or<br />
<br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace;">BusInfo bi = new Models.BusInfo();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace;"> IEnumerable<businfo> model = bi.getDataJ();//gets data in json form from web service</businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace;"> ViewData["PageTitle"] = "Business Information";</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace;"> return View(model);</span><br />
<br />
depending on whether I want to get Json or Xml.<br />
<br />
I have 3 Xml retrieval methods. The default one used above places the Xml data in a DataSet, then to the list.<br />
The 2nd, getDataX2, has no middleman. Data goes from Xml to list, via XmlReader.<br />
The 3rd, getDataX3, converts Xml to Json, thence to list.<br />
<br />
The class is below:<br />
<br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using System;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using System.Collections.Generic;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using Newtonsoft.Json;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using Newtonsoft.Json.Linq;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using System.Data;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using System.Web;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using System.Web.Mvc;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using System.Net;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using System.Runtime.Serialization.Json;//used in getDataJ</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using System.Xml;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">using System.Xml.Linq;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">namespace SiteName.Models</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public class BusInfo</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public string title { get; set; }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public string url { get; set; }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public string description { get; set; }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public string keywords { get; set; }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public string category { get; set; }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> readonly string baseUrij = "http://api.sba.gov/rec_sites/all_sites/keywords.json";//json</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> readonly string baseUrix = "http://api.sba.gov/rec_sites/all_sites/keywords.xml";//xml</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public BusInfo()</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> : base()</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> //this constructor is needed if using getDataX2 because:</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> //we need an alternative while looping through the reader, to setting a BusInfo instance for each group of properties</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> //in order to Add to List<businfo> because the list ends up with all members set to the value of the last iteration</businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> //ie, bi.Add(b) just puts a reference to 'b' in each row when set inside the reader. change b, change every member of bi</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> //instead we're setting local variables that are fed directly into bi.Add as a new BusInfo() for each iteration</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public BusInfo(string t, string u, string d, string k, string c)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> title = t;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> url = u;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> description = d;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> keywords = k;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> category = c;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public List<businfo> getDataJ()//for json source, json to list</businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string uri = baseUrij;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> WebRequest wr = WebRequest.Create(uri);</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> WebResponse wrs = wr.GetResponse();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(List<businfo>));</businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> List<businfo> bi = (List<businfo>)jsonSerializer.ReadObject(wrs.GetResponseStream());</businfo></businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> return bi;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }//end getDataJ</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public List<businfo> getDataX()//for xml source xml to dataset to list</businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> //parent node in dataset becomes 'sites_id' in place of 'sites site'</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string uri = baseUrix;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> HttpWebRequest wr = (HttpWebRequest) WebRequest.Create(uri);</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> wr.Method = "GET";</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> List<businfo> bi = new List<businfo>();</businfo></businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> DataSet ds = new DataSet();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> ds.ReadXml(uri);</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (ds != null)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (ds.Tables.Count > 0)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> foreach (DataTable dt in ds.Tables)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> foreach (DataRow dr in dt.Rows)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> BusInfo b = new BusInfo(); </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> foreach (DataColumn dc in dr.Table.Columns)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> switch (dc.ColumnName)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "title":</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> b.title = dr[dc.ColumnName].ToString().Trim();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "url":</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> b.url = dr[dc.ColumnName].ToString().Trim();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "description":</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> b.description = dr[dc.ColumnName].ToString().Trim();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "keywords":</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> b.keywords = dr[dc.ColumnName].ToString().Trim();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "category":</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> b.category = dr[dc.ColumnName].ToString().Trim();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> default:</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bi.Add(b);</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> return bi;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }//end getDataX</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public List<businfo> getDataX2()//for xml source xml to list direct - no middleman</businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> List<businfo> bi = new List<businfo>();</businfo></businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string uri = baseUrix;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string em = "";</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> XmlReaderSettings settings = new XmlReaderSettings();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> settings.IgnoreComments = true;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> settings.DtdProcessing = DtdProcessing.Parse;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> int bc = 0;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bool runBiAdd = false;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> try</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> using (XmlReader reader = XmlReader.Create(uri, settings))</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> //cannot use an instance of BusInfo inside reader - must use local variables</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string btitle = "";</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string burl = "";</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string bdescription = "";</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string bkeywords = "";</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string bcategory = "";</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> while (reader.Read())</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> { </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (reader.NodeType == XmlNodeType.Element)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = false;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> switch (reader.Name)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "title":</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc++;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> btitle = reader.ReadString().ToString();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = true;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "url":</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc++;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> burl = reader.ReadString().ToString();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = true;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "description":</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc++;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bdescription = reader.ReadString().ToString();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = true;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "keywords":</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc++;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bkeywords = reader.ReadString().ToString();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = true;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "category":</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc++;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bcategory = reader.ReadString().ToString();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = true;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> default:</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (runBiAdd = true && bc == 5)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bi.Add(new BusInfo(btitle,burl,bdescription,bkeywords,bcategory));//see notes by constructor above</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc = 0;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> catch (Exception ex)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> em = "An Error Occured: " + ex.Message;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bi.Clear();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> return bi;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }//end getDataX2</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> //gets xml into json, then into list</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> //have to know structure of xml schema</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public List<businfo> getDataX3()</businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> List<businfo> bi = new List<businfo>();</businfo></businfo></span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string uri = baseUrix;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bi.Clear();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string em = "";</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> XmlReaderSettings settings = new XmlReaderSettings();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> settings.IgnoreComments = true;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> settings.DtdProcessing = DtdProcessing.Parse;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> XmlDocument doc = new XmlDocument();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> try</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> using (XmlReader reader = XmlReader.Create(uri, settings))</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> while (reader.Read())</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> doc.Load(reader);</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string json = XMLToJson.XmlToJSON(doc);</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> JObject jo = JObject.Parse(json);</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> foreach (var v in jo["sites"]["site"])</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> BusInfo b = new BusInfo();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> b.title = v["title"].ToString();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> b.url = v["url"].ToString();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> b.description = v["description"].ToString();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> b.keywords = v["keywords"].ToString();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> b.category = v["category"].ToString();</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bi.Add(b);</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> catch (Exception ex)</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> em = "An Error Occured: " + ex.Message; </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> return bi;</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }//end getDataX3</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #ffe599; color: #cc0000; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><br />
<br />Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-63582860623747240412014-05-22T11:24:00.000-07:002014-05-22T11:34:13.629-07:00Using XmlReader and XmlReaderSettings in C3 Asp.Net MVCI already had methods for retrieving both Json and Xml formatted data from an API web service.<br />
What I still couldn't get to work was getting the data in Xml and converting it cleanly to Json.<br />
Problem thus far are the child nodes and the fact that the conversion methods kept leaving escape slashes in the Json string, despite running it through Regex.Unescape.<br />
<br />
And in truth, there may be no logical reason why I should need to do such a conversion, since my other 2 methods cleanly placed data from both formats into my webgrid's class.<br />
<br />
My Xml method did it by first reading all the data into a dataset, from whence the data went into my class List feeding the webgrid.<br />
<br />
I wanted another way of dealing with the Xml, for better, worse, or just for variety and learning sake.<br />
Thanks to this <b><a href="http://asp-net-example.blogspot.com/2009/05/xmlreadersettings-how-to-use.html">great blog article by Saiful Alam</a></b>, at <b><a href="http://asp-net-example.blogspot.com/2009/05/xmlreadersettings-how-to-use.html">http://asp-net-example.blogspot.com/2009/05/xmlreadersettings-how-to-use.html</a><b>, I got my 2nd Xml to List method.</b></b><br />
<br />
<br />
<div class="MsoPlainText" style="margin: 0in 0in 0pt;">
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;">public List<businfo> getDataX2()//for xml source xml to list direct - no middleman</businfo></span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> List<businfo> bi = new List<businfo>();</businfo></businfo></span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string uri = baseUrix;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string em = "";</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> XmlReaderSettings settings = new XmlReaderSettings();</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> settings.IgnoreComments = true;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> settings.DtdProcessing = DtdProcessing.Parse;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> int bc = 0;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bool runBiAdd = false;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> try</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> using (XmlReader reader = XmlReader.Create(uri, settings))</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> //cannot use an instance of BusInfo inside reader - must use local variables</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string btitle = "";</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string burl = "";</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string bdescription = "";</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string bkeywords = "";</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> string bcategory = "";</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> while (reader.Read())</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> { </span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (reader.NodeType == XmlNodeType.Element)</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = false;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> switch (reader.Name)</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "title":</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc++;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> btitle = reader.ReadString().ToString();</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = true;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "url":</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc++;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> burl = reader.ReadString().ToString();</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = true;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "description":</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc++;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bdescription = reader.ReadString().ToString();</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = true;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "keywords":</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc++;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bkeywords = reader.ReadString().ToString();</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = true;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> case "category":</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc++;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bcategory = reader.ReadString().ToString();</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> runBiAdd = true;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> default:</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (runBiAdd = true && bc == 5)</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bi.Add(new BusInfo(btitle,burl,bdescription,bkeywords,bcategory));//see notes by constructor above</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bc = 0;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> catch (Exception ex)</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> em = "An Error Occured: " + ex.Message;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> bi.Clear();</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> return bi;</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }//end getDataX2</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span>
One issue I didn't consider while making this method, was the bugaboo when I attempted to keep reusing an instance of my BusInfo class, to add to my List<businfo> during the reader's iterations.</businfo><br />
As those of you who are already laughing at me already knew (however many "those-of-you"s there are), within the scope of this code, setting properties of a BusInfo instance for each iteration of the reader, in order to then add to the list, eg: BusInfoList.Add(BusInfoInstance), ends up changing all previous items in the list to the latest, and not so greatest, property values added to the newest item.<br />
To fix this, I gave the class a constructor override with the 5 class properties as parameters, hence giving me the list.Add line "<span style="background-color: #fff2cc; color: #990000; font-family: 'Courier New', Courier, monospace; font-size: x-small;">bi.Add(new BusInfo(btitle,burl,bdescription,bkeywords,bcategory));"</span><br />
<span style="background-color: #fff2cc; color: #990000; font-family: 'Courier New', Courier, monospace; font-size: x-small;"><br /></span>
The constructors I added to the class:<br />
<br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;">public BusInfo()</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> : base()</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> public BusInfo(string t, string u, string d, string k, string c)</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> title = t;</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> url = u;</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> description = d;</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> keywords = k;</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> category = c;</span><br />
<span style="background-color: #ffe599; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span><br />
<br />
<span style="background-color: #fff2cc; color: #990000; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div class="MsoPlainText" style="margin: 0in 0in 0pt;">
</div>
Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-91844973061404820662013-12-06T05:55:00.001-08:002013-12-06T05:58:42.650-08:00RowCount is now a No-Account - Alternative for Setting Dynamic Top RowsHad an issue come up in a couple of old stored procedures we needed to update, to replace the deprecated 'Set ROWCOUNT' with 'Top' for passing the number of rows we wanted selected.<br />
<br />
ROWCOUNT was great for this for one reason, that being it provided an easy way to pass in a request for either some rows, or ALL rows, without knowing how many rows were in the table(s) beforehand.<br />
All you needed to do was pass in 0 to get all rows. Any other amount got up to that many rows.<br />
<br />
Well, I know ROWCOUNT has been deprecated and don't want to wait to find we're moving the databases to a newer server where it won't work, so I figure I'd just convert all such instances to use 'Top' instead. <br />
In ignorance I thought I'd be able to set Top to 100% whenever the parameter passes in 0. NO GO, because Top followed by parentheses requires an integer, and Top followed by the @Setting variable without parentheses won't work. <br />
Seemed my only solution was one of the following:<br />
1: Use the variable setting and convert the query to dynamic sql:<br />
<br />
eg: <br />
<br />
<span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;"><span style="color: blue;">declare</span></span> @p <span style="color: blue;"><span style="color: blue;">int</span></span> <span style="color: grey;"><span style="color: grey;">=</span></span> 4 --pretend this is the incoming parameter</span><br />
<span style="font-family: "Courier New", Courier, monospace;">
<span style="color: blue;"><span style="color: blue;">declare</span></span> @v <span style="color: blue;"><span style="color: blue;">nvarchar</span></span><span style="color: grey;"><span style="color: grey;">(</span></span>10<span style="color: grey;"><span style="color: grey;">)</span></span></span><br />
<span style="font-family: "Courier New", Courier, monospace;"><span style="color: grey;"><span style="color: grey;">
</span></span><span style="color: blue;"><span style="color: blue;">declare</span></span> @sql <span style="color: blue;"><span style="color: blue;">nvarchar</span></span><span style="color: grey;"><span style="color: grey;">(</span></span><span style="color: magenta;"><span style="color: magenta;">max</span></span><span style="color: grey;"><span style="color: grey;">)</span></span></span><br />
<span style="color: grey;"><span style="color: grey; font-family: "Courier New", Courier, monospace;">
</span></span><span style="color: blue;"><span style="color: blue;"></span></span><br />
<span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;"><span style="color: blue;">if</span></span> @p <span style="color: grey;"><span style="color: grey;">></span></span> 0</span><br />
<span style="font-family: "Courier New", Courier, monospace;">
<span style="color: blue;"><span style="color: blue;">set</span></span> @v <span style="color: grey;"><span style="color: grey;">=</span></span> <span style="color: red;"><span style="color: red;">' Top '</span></span><span style="color: grey;"><span style="color: grey;">+</span></span> <span style="color: magenta;"><span style="color: magenta;">cast</span></span><span style="color: grey;"><span style="color: grey;">(</span></span>@p <span style="color: blue;"><span style="color: blue;">as</span></span> <span style="color: blue;"><span style="color: blue;">nvarchar</span></span><span style="color: grey;"><span style="color: grey;">)</span></span> <span style="color: green;"><span style="color: green;">--to limit rows</span></span></span><br />
<span style="color: green;"><span style="color: green; font-family: "Courier New", Courier, monospace;"></span></span><br />
<span style="font-family: "Courier New", Courier, monospace;"><span style="color: blue;"><span style="color: blue;">else</span></span><span style="color: blue;"><span style="color: blue;"> set</span></span> @v <span style="color: grey;"><span style="color: grey;">=</span></span> <span style="color: red;"><span style="color: red;">''</span></span><span style="color: green;"><span style="color: green;">--to draw all rows</span></span></span><br />
<span style="font-family: "Courier New", Courier, monospace;"> <span style="color: blue;"><span style="color: blue;">set</span></span> @sql <span style="color: grey;"><span style="color: grey;">=</span></span> <span style="color: red;"><span style="color: red;">N'select '</span></span><span style="color: grey;"><span style="color: grey;">+</span></span> @v <span style="color: grey;"><span style="color: grey;">+</span></span> <span style="color: red;"><span style="color: red;">' * from table'</span></span></span><br />
<span style="font-family: "Courier New", Courier, monospace;"><span style="color: red;"><span style="color: red;">
</span></span><span style="color: blue;"><span style="color: blue;">exec</span></span> <span style="color: maroon;"><span style="color: maroon;">sp_executesql</span></span><span style="color: blue;"><span style="color: blue;"> </span></span>@sql</span><br />
<br />
With variable holding either the string ' Top [a number] ' or a blank string to allow all rows to be selected, depending beforehand on whatever the parameter held.<br />
<br />
That wasn't a problem to me for a simple query, but we have complex queries with loads of joins, specific select fields, subqueries, function calls, where conditions involving both local variables and table columns, etc. To have to place all of that in an nvarchar @sql string stinks.<br />
<br />
2: Second thought was just having 2 versions of the query, one with the Top included to take the integer value of the parameter when it was above 0, and the second version of the query with out 'Top'.<br />
Again, easy enough if the query is simple, but unworkable when it is complex, with a ridiculous amount of repeated code, and 2 sets of everything to have to maintain when changes are made.<br />
<br />
3: Perhaps the best solution in the end for simplicity, but it felt dirty to me.<br />
If parameter is 0, reset it arbitrarily to the maximum value its datatype would hold, eg: 9223372036854775808 for a bigint, 2147483648 for an int, etc.<br />
Then regardless of parameter value, you'll use 'Top (parameter value) ' in the query.<br />
You'll know if your table might have more rows than this arbitrary ceiling, and not too many needing this solution would, but this solution just smelled to me. I don't like having to pull numbers out of a hat like that and employ them in a jillion procs. Just doesn't feel clean to me.<br />
<br />
4: This method uses a CTE:<br />
<br />
<span style="font-family: "Courier New", Courier, monospace;">declare @rc int --rowcount value</span><br />
<span style="font-family: "Courier New", Courier, monospace;">set @rc = 3 --if set to 0 all rows get returned, otherwise the number of @rc rows</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> </span><br />
<span style="font-family: "Courier New", Courier, monospace;">;with #CTE as (select * from table where whatever ='whatever')</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> select * from #CTE where @rc = 0 --means all rows</span><br />
<span style="font-family: "Courier New", Courier, monospace;"> union select top (@rc) * from #CTE where @rc > 0 --means limited rows</span><br />
<br />
This way, the real query is only typed in once, as the (select) for the CTE.<br />
Using the union gets around the CTE limitation of only working with 1 select statement.<br />
Only one part of the union will matter, so it's like being able to set 'Top' using an if/else. No need to set arbitrary limit set on rows.<br />
It resulted, in my case anyway, in 2 index scans on the table in my proc, accounting for 78% of the work, and the union merge took 21%. I don't know yet the performance implication this has on a humongous query.<br />
Worse comes to worse, I resort to choice #3.<br />
Anybody out there have a better way to do this?Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-24284606190076196172013-11-14T07:32:00.001-08:002013-11-14T07:37:15.469-08:00Always Make Sure it's Plugged into the Wall! SQL Remote Connection into a Named Instance Getting started using SAP BODS (Business Object Data Services). My testing playground are my 2 local SQL servers, the main SQL Server 2008 R2, and its stepbrother, SQLEXPRESS.<br />
The jobs run on SAP don't run locally from my repository, but from a central network server. <br />
Didn't realize that at first; had to learn the hard way.<br />
Couldn't figure out for the life of me why executing jobs worked fine connecting with the my main SQL Server 2008 R2, which doesn't depend on a named instance, while the Express server could never be found.<br />
Even after realizing, upon combing through the job's error output, that these jobs were not being locally executed, it didn't dawn on me right away that the Named Instance nature of the express server was the real issue.<br />
I'm kinda dense that way sometimes.<br />
Anyhoo, after combing back and forth like an ocean tide over all the configuration and security settings of the express server and my PC, looking for the magic bullet or best suspect to arrest, I finally received the epiphany.<br />
The remote server executing the jobs only knew my local machine's name, which by default pointed to the main SQL server without needing a named instance. Adding the express's name to that was the equivalent of speaking in tongues to the job server, with it being an atheist. <br />
No named instance, fine, let's get to it and work.<br />
Named instance, "like, DUH??? Which way do I go George, which way do I go...?"<br />
Supposedly there's always got to be one, but when Googling tech issues, you're lucky to even find one real solution, or even a mere clue to one.<br />
Turned out, all I needed to do was turn the SQL Server Browser service on, along with making SQLEXPRESS's TCP/IP enabled (in SQL Server Configuration Manager under the server's protocols), which I'd already done further back in the process of futility.<br />
Bang, boom! Named instance found! Job complete.<br />
One last little thing, in express's TCP/IP protocol settings, I had to make sure what was listed under IPAll for dynamic ports, was set as THEE port for it, because the normal default SQL port, 1433, was already taken by 2008 R2.<br />
I just cut the port number from Dynamic ports and pasted into 'TCP Port'.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-46702467802076502742013-11-12T12:18:00.002-08:002013-11-12T12:18:48.893-08:00Proxy Fight and How to Be CredentialWe had a devil of a time trying to figure out how to get an SQL Server Agent Job to run 3 DTSX packages that needed to collect their source data from 2 outside database servers.<br />
The Server Agent by default executes all its jobs with its own service account as the user. Well, that didn't sit well with the other 2 databases, who didn't give a rats butt about that user - they weren't letting him/her/it in.<br />
Finally figured out we could swap that default user with one that was a recognized user on the other 2 servers.<br />
We had to set that user up as a Credential. In object Explorer, go to Security, and then right click to set up a new Credential. I just put the acceptable user id in as both the Credential name and Identity, along with that user's network pw. I left Encryption provider unchecked.<br />
Then I set up the same as a proxy under SQL Server Agent.<br />
Then I changed the default 'Run As' on each job step to the new proxy, which now came up as a drop menu choice.<br />
Badda bing, bang, boom, the job now worked.<br />
Once we were able to get our server's service account set up as a user on the other 2 servers, we switched the 'run-as' back.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-23135211570592285742013-09-23T07:53:00.001-07:002013-09-23T07:53:54.943-07:00Confounded Connection SettingsDidn't realize how drastically setting SQL connections changed from .Net v2 to .Net v3.5 and above.<br />
Any old connections you have that were kept under 'appSettings' in web.config need to be moved to 'connectionStrings' and reformatted.<br />
The way you then set those connections in your code-behind also must be changed.<br />
<br />
This page has a great explanation of this:<br />
<a href="http://www.connectionstrings.com/store-connection-string-in-webconfig/">http://www.connectionstrings.com/store-connection-string-in-webconfig/</a><br />
<br />
Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-72263246358387935442013-09-23T07:32:00.003-07:002013-09-23T07:32:54.627-07:00See Session Variable Values in Visual Studio BreakpointsSome developers aren't aware, or forget, how to see the breakpoint values of Session variables while debugging. Sometimes Visual Studio can test your breaking point in order to use breakpoints.<br />
Mouse over the variable and the icon for a drop menu will appear.<br />
Under 'Session', go to 'Keys'.<br />
Under that, go to '_coll'.<br />
Then open either '_entriesArray', if you know the variable's subscript, or '_entriesTable' to scroll through the variable names.<br />
Open the subscript/name to find the key/value settings and click on the value.<br />
<br />
If anyone knows how to bypass all this hoop jumping to get this info, I'd be much obliged.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-27227549953423111112013-09-23T07:22:00.000-07:002013-09-23T07:22:04.961-07:00Confounded ConfigurationsIf you maintain different build configurations in Visual Studio .Net projects/websites, make sure you know which one is set as the active configuration whenever you go to do a debug run or publishing.<br />
Always check Configuration Manager under the 'Build' menu before proceeding and change the Active solution configuration as needed.<br />
Mine usually differ only in the SQL connections, each config having its own lil' ole mini web.config file (eg: Web.Release.config) for swapping the standard web.config connections with those needed by the specific configuration.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-87173687448607736142013-09-23T07:03:00.000-07:002013-09-23T07:03:09.099-07:00Great Page Explaining Stored Procedure Speed Issues
<br />
<div class="MsoNormal" style="margin: 0in 0in 0pt;">
<span style="font-family: Calibri;">Had an issue with an SQL Server stored procedure running far slower than the same
code as a stand alone query.</span></div>
<div class="MsoNormal" style="margin: 0in 0in 0pt;">
<span style="font-family: Calibri;">It was running a totally different execution plan due to the
parameters.<o:p></o:p></span></div>
<span style="font-family: Calibri;">This page explains how all that happens. The key to my issue
was in the section ‘The Default Settings’<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 0pt;">
<a href="http://www.sommarskog.se/query-plan-mysteries.html"><span style="color: blue; font-family: Calibri;">http://www.sommarskog.se/query-plan-mysteries.html</span></a><o:p></o:p></div>
<br />
<span style="font-family: Calibri;">Pouring through the execution plans for procs can be an eye opener. I've found myself vastly improving performances with seemingly minor changes, such as reordering the join elements, adding indexes if missing on join columns, and in one case, using 'Forceseek' to stop the server from using a particular index and instead use a different one.</span><br />
<span style="font-family: Calibri;"></span><br />
<span style="font-family: Calibri;">Just be aware that a new index that makes your current proc zoom, could adversely affect another proc using that table.</span>Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-22247497253081095932013-09-23T06:39:00.002-07:002013-09-23T06:44:14.747-07:00Ah Ha Moment of the Day - Where's This Master Page Coming From?I'm obviously not a certifiable Visual Studio Guru yet. Ran into a situation many other Dot Net Developers may have, and not even realized it.<br />
I had to revised a couple of Webform pages, moving something from one to the other. Seemingly a simple enough task.<br />
Everything was fine until I did a local publish before submitting for deployment to Stage.<br />
Unlike my local debug build, which produced no errors, this publish generated javascript errors on one page. Since I hadn't changed one single character on any JS or jquery code, I was at a loss.<br />
The offending code was jquery and I feared a conflict maybe between it's dollar symbol and that used in the Telerik library, but ruled that out since no other page, all including both libraries, was generating this error.<br />
At that point I started combing through my source codes and that from the browser, and poured through the master file included in the opening content page tag. I found some archaic 'script src' tags in the offending page that I thought perhaps should be in the master file instead. For all I knew, maybe one of my changes to the form structure was causing something to be read or executed in a different order than previous.<br />
So I start shifting tags from content page to master, rebuild and WTF????????<br />
Nothing I added to the master page was in the new content page source code!!!<br />
I finally discovered, upon going through the various master page files, that despite the master page referenced in the content page, a totally different master page was being used. I confirmed this was the case after making tiny revisions in both and seeing the second master was definitely the one included in the build.<br />
In the end, I fixed the jquery error by including a library script that I saw was in the other content page, which also had the same jquery method and wasn't throwing the error. Whatever the reason why my local debug build didn't throw the error, I wasn't about to fight with the Stage build to find out why. I gave it want it apparently wanted, returned the master pages to their original state, error gone.<br />
BUT, I still wanted to know how the hell was the hard coded master page being swapped out and by what setting, or process? I'd already gone back and forth through all the Visual Studio menus I figured might be doing this via some project level setting.<br />
Finally I discovered that Global.asax.cs was overriding the hard coded master with the second one. Learn something new every day. Had never considered that prior. Makes perfect sense if you don't want to risk globally changing the opening tag of every page on your site.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-9898505126628434892013-03-08T04:53:00.001-08:002013-09-23T06:52:18.805-07:00VB.NET Fixing vb.net system.windows.forms.axhost+invalidactivexstateexceptionThe hell dreaded vb.net system.windows.forms.axhost+invalidactivexstateexception error is probably the plague of many converting old VB6 applications to VB.NET, especially if, like me, you're new to working with either.
Finally, finally, I stumbled upon a forum snippet on <a href="http://www.codeproject.com/">www.CodeProject.com</a>, page <a href="http://www.codeproject.com/Questions/55699/AxHost-InvalidActiveXStateException">http://www.codeproject.com/Questions/55699/AxHost-InvalidActiveXStateException</a>, and the guy's problem wasn't even mine, and wasn't even fixed, but one lil ole line of code he had fixed my issue, at least a few of them.
Add controlname.CreateControl() in your form's designer page, before the rest of its properties are set.
In my forms it was Me.controlname.CreateControl().
For whatever reason, Visual Studio 2008 saw fit to not include this in its code conversion.
Almost got sucked into other forum opinions that you need special Active X licenses to get such legacy controls to work in .NET.<br />
UPDATE: My suggestion above isn't for every such situation. On some forms I found that it was not a factor at all. Rather it was the way .Net forms are loaded from the form calling on them.<br />
I had to switch the positioning of the first code accessing the values of any Active X elements to be after the 'Show' and/or 'Activate' commands for the form in which those elements reside.<br />
Apparently, VB6 wasn't so concerned about certain things that VB .Net obsesses over.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-80005179474837031412013-01-19T13:26:00.001-08:002013-01-19T13:26:48.470-08:00Robert Saylor dies after being handcuffed at Frederick movie theater | WJLA.com<a href="http://www.wjla.com/articles/2013/01/robert-saylor-after-being-handcuffed-at-frederick-movie-theater-84206.html#.UPsOnx6WggE.blogger">Robert Saylor dies after being handcuffed at Frederick movie theater | WJLA.com</a><br />
<br />
Better be effective followup by the news media and law enforcement on this. These employees' and deputies' actions better be scrutinized to the nth degree. Where was Saylor's aide companion when they confronted and agitated him? They couldn't see he likely had cognitive issues? Sure sounds like negligent homicide to me.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-14325494802010194522012-11-20T11:26:00.002-08:002012-11-20T11:39:15.562-08:00Zend, Zend, What Have you Done Now?To paraphrase the Sam Jaffe character from the Flintstones send-up of Ben Casey, (Ben Caserock?), "Zend, Zend, What have you done now, Zend?<br />
Yet another installation that the designing company imagines is a snap to get done.
I decided I wanted to play with the Zend framework, because I like to torture myself.
I decided against the all inclusive Zend Server, as I didn't need any more PHP installations, and looked to add ZF2 to my WAMP server instead.
I placed the framework directories inside WAMP and created another directory to be my Zend playground.<br />
I then did the recommended Composer thingee to get the sample skeleton project installed, but the official instructions didn't exactly go according to plan.
Instead of running `php composer.phar self-update`, followed by `php composer.phar install` in the DOS prompt window, I first ran `composer self-update` as per someone's suggestion, but not entirely per their suggestion.<br />
The suggestion had added that I should remove the .PHAR from the file name. Instead, what I really did was run the composer.bat file instead of the PHAR file.
I then had to copy the composer.json file to my root C directory.
The sum total of the json file is:
<pre>
{
"require": {
"monolog/monolog": "1.2.*"
}
}
</pre>
Just make it in notepad.
Then I ran `composer install` from the C prompt and got the skeletons out of their closet.
That was not the end, however.
Some virtual hosting had to be done.
<br />
Made all my preferred playground directory localhost aliases in Windows hosts file, created a playgrounddirectory.com.conf file in WAMP's vhosts directory, added the requisite <Directory> and <VirtualHost 127.0.0.1> groups to Apache's httpd-vhosts.conf file.
<br />
But still, the WAMPstones characters personalities are mixed up.
One more little detail still needed to be attended to.<br />
Had to add to Apache's httpd.conf file, the line `SetEnv ZF2_PATH "c:/wamp/ZendFramework203/library"`, the location where I chose to store Zend.(Zend came by default as `ZendFramework-2.0.3`, but I'm prejudiced against hyphens and periods)<br /> I could have just called it `library`, or `stupid`, or anything, I suppose. As long as the Zend subdirectory within library could be found.
Zend Caserock has finally returned all the WAMPstones personalities back to their proper characters.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-66657482476656892252012-10-17T12:46:00.001-07:002012-10-17T12:49:32.976-07:00Port 80 - The Friday the 13th of Web Server IssuesTo paraphrase the late Ronald Reagan, after <strong>installing WebMatrix 2</strong>, "There you go again!"<br />
Of course no sooner was <strong>WebMatrix 2</strong> in use, I found my <strong>Wamp Server</strong>, which I now regret assigning to port 80, failing to start again. <strong>Apache</strong> couldn't open its logs.<br />
The long and the short of this is:
<br />1: The culprit was one that came back from the dead, <strong>Web Deployment Agent Service</strong>, resurrected by <strong>WebMatrix</strong>, which I needed for hosting MicroHard's <strong>IIS Express</strong> on my old creaky <strong>Windows XP</strong> system.
<br />2: The solution (I hesitate to label it Final Solution, for both sensitivity and expectation issues), is to go into your registry.
<br />3: First go into services from control panel/administrative tools, and stop that service.
<br />4: Then go to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
<ul><li>
Scroll down the long list to MsDepSvc</li>
<li>Choose Parameters, and open ListenUrl to modify.</li>
<li>By default, unless you custom installed from the get go, should be: http://+:80/MsDeployAgentService</li>
<li>Change the 80 to whatever port you want to fob theis service off to.</li>
<li>In my case, I chose 8080. New value: http://+:8080/MsDeployAgentService</li>
</ul>
<br />5: Reboot.
<br />
Keep track of your server ports, if you're like me and have begun to collect web servers like coins. I gave 8081 to Bitnami, 8082 to SQL reporting services, etc.
Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0tag:blogger.com,1999:blog-4151654647522754199.post-32157283966241628672012-10-04T14:50:00.002-07:002012-10-04T14:53:41.815-07:00jQuery $.getJSON is NOT Jason from Friday the 13thAlthough at times $.getJSON can certainly seem like a maniacal mass murderer to those not used to working with it.<br />
Tips for the unwary and clues for the clueless.<br />
When iterating through data returned by $.getJSON, make sure you know when to refer to the subscripts as numeric arrays as opposed to associative arrays.<br />
EG: From a typical json file:<br />
<br />
<br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">"customers": [</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{ "id":1,"name":"John Doe" },</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{ "id":2,"name":"Sand Wich" },</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{ "id":3,"name":"Meanmissus Jones" },</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{"id":4,"name":"Hung Lo"},</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{"id":5,"name":"Cardin Naal"}</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">],</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">"magazines": [</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{ "id":1,"name":"Field and Wild","rate":29.99 },</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{ "id":2,"name":"Car and Driven","rate":34.95},</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{ "id":3,"name":"Unpopular Scientists","rate":42.95 },</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{"id":4,"name":"TV Lied","rate":19.99},</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">{"id":5,"name":"Readers Indigestion","rate":24.99}</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">],</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">"subscriptions": </span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{"1": [{"id":2,"startdate":"01/01/2012","enddate":"01/01/2013"},</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{"id":4,"startdate":"01/01/2012","enddate":"01/01/2014"},</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{"id":5,"startdate":"01/01/2011","enddate":"01/01/2013"}</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>],</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>"2": [{"id":1,"startdate":"01/01/2011","enddate":"01/01/2013"},</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{"id":3,"startdate":"01/01/2012","enddate":"01/01/2015"},</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{"id":5,"startdate":"01/01/2011","enddate":"01/01/2012"}</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>],</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>"3": [{"id":2,"startdate":"09/01/2011","enddate":"09/01/2012"},</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{"id":3,"startdate":"01/01/2012","enddate":"01/01/2014"},</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{"id":4,"startdate":"06/01/2010","enddate":"06/01/2012"}</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>],</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>"4": [</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{"id":4,"startdate":"01/01/2012","enddate":"01/01/2015"}</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>],</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>"5": [{"id":1,"startdate":"01/01/2011","enddate":"01/01/2013"},</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{"id":2,"startdate":"06/01/2011","enddate":"06/01/2013"}</span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>]}</span><br />
<span class="Apple-tab-span" style="background-color: #fce5cd; white-space: pre;"><span style="color: #741b47; font-size: x-small;"> </span></span><br />
<span style="background-color: #fce5cd; color: #741b47; font-size: x-small;">}</span><br />
<span style="background-color: white; color: #741b47; font-size: x-small;"><br /></span>
<br />
Say you're in a for loop, using i as the iterator to run through subscriptions, and starting i at 1:
data.subscriptions[i] does NOT equal data.subscriptions[1], as in the 2nd subscript of a numeric array.
It equals data.subscriptions['1'], with '1' (variable i's value) being the key, and the 3 groups of subscription data following it as the value (itself a numeric array in this case).
For magazines and customers, however, magazines[i] would equate to magazines[1], the 2nd subscript (Car and Driven).
In iterating through subscriptions, we're first going through the associate array from keys 1 through 5.
Each of those contains a numeric array.
If i2 starts at 0 for going through that array and i still ='1':
data2.subscriptions[i][i2].id refers to data2.subscriptions['1'][0].id, the first subscript under key '1', with a value of 2.
data2.subscriptions['1'][1].id equals 4, data2.subscriptions['1'][2].startdate = "01/01/2011", etc, etc.Nawthun Suthnuhhttp://www.blogger.com/profile/07835220690301153588noreply@blogger.com0