Latest Posts
Why? Well, sometimes you just want it all in one table.
create
table #t (
tablename sysname,row_count int,
reserved varchar(50),data varchar(50),
index_size varchar(50),unused varchar(50))
exec
sp_msforeachtable
'insert #t exec sp_spaceused ''?'''
select
*
from #t
drop
table #t
Another in the series of recordings that I have done for INETA Live.
Saturday morning: Learn about Silverlight, WPF, Win 7 Phone
Saturday afternoon: Start coding
Sunday afternoon: Demo Application
YES all these apps were built in less then 24 hrs! We had a great time learning and building all of them. Hope you enjoy watching the fruits of our labor!
Another in the series of recordings I have done for INETA Live.
In this talk Chris starts by giving us an introduction to programming in XAML, covering all the basics. Then he dives into developing Model View ViewModel (MVVM) applications for the Windows Phone 7 using MVVM Light.
Chris Koenig is a Developer Evangelist with Microsoft, based in Dallas, TX. Prior to joining Microsoft in March of 2007, Chris worked as a Senior Architect for The Capital Group in San Antonio, and as an Architect for the global solution provider Avanade. As a consultant, Chris worked with a variety of clients from many vertical markets, ISVs and other solution providers on enterprise-class Windows and web-based applications. Today, Chris focuses on building, growing, and enhancing the developer communities in Texas, Oklahoma, Arkansas and Louisiana.
http://chriskoenig.net
http://twitter.com/chriskoenig
Part 1
Part 2
Part 3
Part 4
Question: how do I regain sysadmin role for myself if I am a local admin, but not a sql sysadmin currently. This scenario can happen for a variety of reasons, but if you are the owner and administrator of a box, how do you get to where you can manage it again? It's pretty simple. Basically stop sql, then start it in single user mode, then add yourself, reset sa, whatever. A sample script is below. This script makes several assumptions.
- Your server doesn't take longer than 10 seconds to start, otherwise modify the sleep line (or just do this manually and wait for it to start)
- You already have an account with access on the server. If you don't you can add it or just reset the SA password. I find that usually the people interested in doing this at least have access to a database on the server so you can just grant that group admin access for the duration of the recovery.
- You don't mind killing the sql server task ungracefully like I'm doing below. If you do mind that, you can always just do all this one step at a time instead of copy and pasting it or something.
- You're server binary is in Q:\MSSQL\MSSQL.9999\MSSQL\Binn\sqlservr. I assume that yours is not which is why I am using this in the script so change the path to wherever yoru sqlservr.exe is actually located.
- You already had sql agent running. If you didn't, you can drop the last line. If you did the first line will automatically end it with the /y
net stop mssqlserver /y
start "sqlserver" Q:\MSSQL\MSSQL.9999\MSSQL\Binn\sqlservr -x -m
sleep 10
sqlcmd -E -S localhost -d master -Q "EXEC master..sp_addsrvrolemember @loginame = N'domainname\somedomaingroupthatalreadyhasanacccount', @rolename = N'sysadmin'"
taskkill /IM sqlservr.exe
net start mssqlserver
net start "SQL Server Agent (MSSQLSERVER)"
Another in the series of recordings that I have done for INETA Live.
Abstract:
The Dynamic Language Runtime (DLR) came out in version 1.0 with the release of .NET 4 but most developers don't know it is there and, if they do, don't know what you can do with it. In this talk we will discuss what the DLR is and, through looking at the plethora of things you can do with it, get a taste for things the DLR allows us as developers to do with it. Many have heard of the Python and Ruby support but this is just the tip of the proverbial iceberg. So come join us for a discussion of the many things you can do with the Dynamic Language Runtime.
Bio:
Eric Sowell is an avid .NET developer who gets into as many technologies as he can though with a focus on ASP.NET. He is a Senior Application Engineer at Match.com on the international platform and enjoys writing code which serves up Html millions of times on a daily basis. Eric is the father of three children and the husband of one wife. He also has fish. When not being a geek or hanging with the family, he enjoys reading, writing and doing research primarily in the realms of ancient Greek, biblical studies and early Christianity.
You can find Eric online in the following places:
• http://www.ericsowell.com
• http://www.thecodinghumanist.com
• http://www.archaicchristianity.com
• http://www.twitter.com/mallioch
So I am a huge fan of LINQPad. I use it all the time for ad hoc data processing mostly because of the .Dump() method which allows me to copy and paste something a little prettier than what I get outta mgmt studio or a simple command line processor. It's really pretty much the same to me, but for some reason normal people seem *wayyyyy* happier when they get a little blue box with some lines instead of just text with tabs or commas =P
Anyway, I was fixing to import some data from a file and I was joining it against the db, but there were some values to lookup that in the import were text files. No big deal, just join the values and get the ids based on the names. This did work, but I was trying to shrink the data being sent/retrieved over the wire so I did a pre-fetch on the distinct values and joined them on the ids on the lookup table. This worked fine, but I found that when I later went to join the object I retrieved against my file imported object, things didn't match. This made me a little crazy for about an hour or two as I kept coming back to it and writing queries that would show more and more of the data. It was particularly annoying because usually I just import this data into a table and do it all in sql, but I figured at some point I wanted this to be some kind of GUI so I'd do it in linqpad in preparation of using EF or Linq2Sql or whatever more .net'ey way of doing things. So since I have done this about 50 times in the past with no problems, it was irritating that it was causing me any time at all. Trying to 'research' what was up with my data caused me to need to do an outer join which is its own particular flavor of silliness (IMO) in LINQ.
So I let it sit overnight. Came back the next day and realized what was up. I was doing a linq2objects compare really because I was crossing the retrieved data (an anon type with just my id and name I joined with the distinct values from my import file) with my import data (a anon type with the stripped lines from my import csv) and linq2objects is case sensitive. For me, I am simply dealing with basic imports with all English chars etc so .ToUpper() on both sides of the compare fixed everything. But if you have to deal with larger international type imports with different globalization/culture concerns, you might need something else.
Anyway, here's a little code snip even though this almost doesn't really warrant one. There are some other ways to 'join' this data, but this is basically going to get the TableInDB and then It will do the compare client side, that's why it fails without the case insensitivity.
var data_with_keys_to_import =
from f in DataImportedFromFile
join t in TableInDB on d.TextValueForKey.ToUpper() equals t.TextValueForKey.ToUpper()
select
new {...};
And here's a few of links about case sensitivity stuff if you can't find your own on google/bing. I found the last one the most poignant.
- http://stackoverflow.com/questions/841226/case-insensitive-string-compare-in-linq-to-sql
- http://blogs.msdn.com/b/michkap/archive/2007/10/01/5218976.aspx
- http://blogs.msdn.com/b/michkap/archive/2005/03/10/391564.aspx
Gather round my water logged cohorts, listen to my story of pain and joy. As with most award winning novels this story starts off in similar fashion…
It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Summer, it was the season of Vacation, we had everything before us, but it was virtual, we were all going direct to migrate content, we were all going to have a good weekend - in short, things were supposed to be a day in the part, that said some of its noisiest authorities insisted on much preparation and testing for the task at hand. So be it, they sign the checks, and all tested well.
The task was to move two content databases from server “A” to dissimilar server “B”. So we test, simple SharePoint backup from “A” to “B”, viola! It works, in DEV. Fast-forward to the night of…Second verse same as the first. After a few network issues around a MSFT Clustering and Juniper switch gear (don’t ask, it’s another post) fiasco we have the web apps created and content DB’s in the restore process. Oh Darn!…It didn't work we now have the following problems to address.
Q1.)Contend DB failed the restore had to manually attach content DB. Ok…
A1.)Manually attach in SQL, GUI add via Central Admin.
Q2.)The SQL Log file drive full and I didn't have admin permissions
A2.)BackUp ContentDB and Shrink Logs and give myself permissions
Q3.)Pay attention!… This is the big one! NOT ALL OF THE SUB SITES ARE ACCESIBLE. But here is the kicker. The content is visible via “Manage Content and Structure” but when I tried to drill down SharePoint said the site had been deleted.
A3.)Bring up Central Admin, Enter Define Managed Paths, and Delete the managed path to the sub site collection in question.
Now let’s try that seemly mystery site again. Viola! IT works in Production.
I hope this little story aids someone in finding their happy ending.
Oh yeah… The END.
Another in the series of recordings I have done for INETA Live.
Experts in today’s leading technologies guide you through current trends. With Microsoft’s newly released Visual Studio 2010 come join Sarika and Kevin as they share their product knowledge and the culture experience at the world’s largest technology company.
SPEAKERS
SARIKA CALLA—Speaking about Microsoft from a woman’s perspective, this native born Indian holds a Masters in Computer Science from Georgia Tech and has been with Microsoft for the past eight years. Sarika is now a Team Lead on the IDE Team.
KEVIN HALVERSON—With seven years as a Microsoft employee, Kevin has expertise in LINQ Expression Trees, Code Model, and COM/Office Interop and has a background as a former Unix Sys Admin.
As I continue my quest to make lemonade out of the proverbial lemons tossed my way during the course of a day I leave you with the following tidbit on codec's.
Since web development really isn't my strong point this many may consider this common sense but for the administrator such as myself codec's are a pain, especially when they don’t play well with Microsoft (or vice versa) and you aren't particularly an expert on them.
The problem: Streaming Application wouldn't play sound on Windows 7 machine because of missing Sipro Lab Telecom ACELP.net codec.
MSFT Solution: A workaround (use a non MSFT multimedia playback program) See MSFT Official Solution
Since The MSFT solution wouldn't cut it for me so I was left a couple of lemons, I mean options, yes options.
- Hack together some JavaScript to id the browser as IE8 or IE8 Compatibility mode(native to Windows 7), set a cookie, prompt the user to self install codec and redirect to the Streaming application.
- Deploy the ACELP.net codec to all the users via MSFT tools (e.g SCCM, SMS)
- Re-encode the audio stream with a different codec and figure out what XML file was referencing the original audio.
Obviously choice number one sounded best since it seemed kind of convoluted, insecure, and prone to failure. But that conclusion was only made after I wrote the darn thing and realized “Dude, the browser thinks your code is malicious”
Choice number two would have worked but then my counterparts who manager those systems were in the middle of upgrading them and wanted to focus on that before anything else (go figure).
That left me with Choice number three, so out came the MSFT Expression tool which promptly converted the original audio to a windows native codec. Change of file name in the XML config file on the streaming media and all is well.
I am please to officially announce that OpenCamp Dallas has added a .NET Track, and what a .NET Track it will be.
http://www.OpenCa.mp
What is OpenCamp?
OpenCamp is the SouthWest’s first multi-platform web conference. With top speakers covering topics ranging from social media to technical development, content creation, revenue generation and more, webmasters and web developers, bloggers, podcasters and technologists on any platform are welcome.
In the morning, we’ll have general sessions which everyone will attend. The topics will include promotion, marketing, SEO, monetization, and more. Chris Pirillo, Cali Lewis and Brian Clark (aka Copyblogger) are just a few names confirmed who will speak during the General sessions. In the afternoon, we’ll break out into CMS specific sessions- WordPress, Joomla!, Drupal, .NET, and New Media- where people will be able to dig deeper into their platform of choice, or learn what they can do with a new platform. The event is scheduled for August 27-29th and we’re expecting over 1,000 attendees!
What’s in the .NET Track?
Caleb Jenkins: .NET on the cheap. (Free and OSS resources from the Redmond Giant)
Chris Koenig: Windows Phone 7 Up Close
Eric Shafer: E-commerce in DotNetNuke
Jason Kergosien: Social Communities in DNN
Todd Stone: Building Web Sites with mojoPortal
Tony Valenti: Build a Basic Website with DotNetNuke
Everyone Registering for the .NET Track will be entered into a drawing to win a FREE copy of Visual Studio 2010 Ultimate with MSDN a $11,899 value.
What else is at the conference?
- Social Media
- Monetization
- Audio Podcasting
- Video Podcasting
- WordPress
- Joomla
- Drupal
How much does it cost?
- Student $99
- Individual $139
- Professional $169
- Business $269
Includes Lunch, WiFi and admission to all the OpenCamp Parties/Networking Events
http://openca.mp/register/
Register before July 31 and use "ugdotnetOC10" to get 20% off
Where to stay?
Attendees staying at the conference hotel have access to some “special OpenCamp hospitality”.
http://openca.mp/about/location/
The conference will include many “Parties/Networking Events” so even if live in Dallas you might want to stay at the hotel.
Help get the word out!
Feel free to forward, re-tweet this post. Also I have attached a PDF Flyer, so what are you waiting for, print it out and hang it up by the water cooler at your office.
Download file
I am speaking tonight at the Central TX .NET UG (http://ctxdnug.net) in Temple, TX (just south of Waco).
Utilizing .Net Generics to Write Better Code
Abstract:
Generics let you tailor a method, class, structure, or interface to the precise data type it acts upon. In this session we will discuss what capabilities Generics provide to you the developer and how to use them in collections, and with delegates. We will also talk about creating your own generic classes and methods.
Event URL:
http://ctxdnug.net/Meetings/July-2010-Meeting.aspx
Announcements PPT
http://cid-80ce78240aa8df49.office.live.com/view.aspx/.Public/20100708%5E_Ineta.ppt
Talk PPT and Notes
http://www.developerroundtable.com/Libraries/Misc_Stuff/20100708_Central_TX_Generics.sflb.ashx?download=true
I needed to take some records in one file, do some stuff with the record, then put the results in another file. The 'do stuff' part was taking a bit longer than I thought it would so I wanted to see status. This sample illustrates taking 1000 records from a source file, uppercasing each line, putting it in another file, and letting us know every 100 lines.
using(TextWriter tw = new StreamWriter(@"uppercase.txt",false))
{
int i = 0;
var q = File.ReadAllLines(@"lowercase.txt").Take(1000);
foreach(var v in q)
{
tw.WriteLine("{0}", v.ToUpper());
//print status on every 100th record
if ((i % 100) == 0) Console.WriteLine("{0}/{1} processed", i.ToString(),q.Count().ToString());
i++;
}
Console.WriteLine("{0}/{1} processed", q.Count(),q.Count().ToString());
}
So the other day I got the following question about reporting on some log data:
The data being loaded is a bunch of machine log files. (E.g. MachineName Status Timestamp) The status is a simple Start or Stop. My question is can I use Datediff between sequential records to determine elapsed time between start and stop? I know this would work if the start and stop data were in the same record and I believe this will work between sequential records but I'm fuzzy on what's best and putting it into action
Below is the end result of my answer. There are three basic parts of the solution below:
- Build some test data and stage it
- Group the data and make some keys to re-join it
- Write a little report to show what we are after
- (bonus) a little pivot table to show some other groupings on the data =D
-- our test data will simulate 10 machines that make 100 total
-- connections per day that last between 1 and 300 seconds.
-- this sample log is stores three items, the box name, what
-- happened (start/stop) and a timedatestamp
-- this data is supposed to happen in a sequence mostly. there
-- could be overlapping time events with the machines, but since
-- we would just eliminate that in a sort by machine later anyway
-- i am not going to worry about that and we will do everything in
-- one long sequence. our start date will be getdate() if there is
-- no date already in the table.
-- this table var will hold our 'raw' data
declare @t table
(
box char(5)
, evt varchar(5)
, tds datetime
)
-- loop to fill in our temp table. basically just some vars and some loops with random info
declare @i int,@ii int, @box varchar(5), @tds datetime
select @i = 0,@ii = 0
while @i < 10
begin
select @box =
'box'
+
CAST(@i as
char(1))
while @ii < 100
begin
select @tds =
coalesce(MAX(tds),getdate())
from @t
insert @t values(@box,
'start', @tds )
insert @t values(@box,
'stop',
dateadd(SECOND,RAND()*300,@tds))
set @ii = @ii + 1
end
select @i = @i + 1, @ii = 0
end
-- this is our 'staging' table that we'd be importing this data into for analysis
declare @tt table
(
box char(12)
, evt varchar(5)
, tds datetime
, group_key int
,
primary
key
clustered (box, evt, group_key)
)
-- this represents our load. we are adding a row_number line to provide
-- a unique extra key for each set of box/evt combos
insert @tt
select box, evt, tds
,
row_number()
over (partition
by box,evt order
by tds) [group_key]
from @t
-- now we can select from our loaded data table twice, once for each
-- of our two events start/stop and join based on the group_key which will
-- already be unique for each set based on our load above.
-- this shows us the data how we want to see it. or at least how i was
-- originally asked for it.
select
starts.box
, starts.tds [start]
, stops.tds [stop]
,
DATEDIFF(ss,starts.tds,stops.tds) [duration]
from
@tt starts
join @tt stops on
stops.evt =
'stop'
and stops.box = starts.box
and stops.group_key = starts.group_key
where
starts.evt =
'start'
-- here is a little pivot table to show you how many connections
-- in the timeframes took certain lengths of time to complete.
-- you could do this a number of ways, but i don't get to use
-- the pivot command enough so i figured i'd tack it on here =P
select
*
from
(
select
box,
case
when duration < 30 then
'<30s'
when duration between 30 and 60 then
'<60s'
when duration between 60 and 120 then
'<120s'
else
'120+s'
end [d]
from
(
select
starts.box
,
DATEDIFF(ss,starts.tds,stops.tds) [duration]
from
@tt starts
join @tt stops on
stops.evt =
'stop'
and stops.box = starts.box
and stops.group_key = starts.group_key
where
starts.evt =
'start'
) ii
) i
PIVOT
(
count(d)
FOR d IN
([<30s],[<60s],[<120s],[120+s])
) p
I had the great pleasure of attending the DFW Silverlight and WP7 DevCamp (Silverlightpalooza) this weekend. http://silverlightpalooza.dynamitesilverlight.com/
Big thanks goes to Teresa Burger & the entire team of volunteers that made this event possible.
Without the financial support of Microsoft WP7 Team and Improving Enterprises, the event wouldn't have happened.
And a big thanks to all the provide prizes: Microsoft WP7 Team, Agilitrain, Expression .toolbox team, telerik, Infragistics, @zainnab, Matrix Resources, Pearson, and Apress.
I also want to thank my team, James, Rap, Krishna, Ron for all your help!
We decided to build a Rovio controller for the Windows 7 Phone. The Rovio is a robotic web camera made by the folks at WowWee (http://www.wowwee.com/en/products/tech/telepresence/rovio/rovio). The Robot sports among other things a nice restful service architecture and a mini web server making sending the instructions to and getting information from the robot as easy as just hitting URL’s. As you can see by the above photo the background of the phone is a stream of camera images from the phone. On the left there are 2 progress bars, the top for WiFi signal strength, and the bottom for battery power. Just to the left of that are three arrows that instruct the robot to move forward, left and right, and a stop button that tells it to stop moving. On the right hand side of the UI are a series of buttons that allow you to put the robots head up, head middle, head down, headlights on, and to tell the robot to go home. At the bottom of the screen is some diagnostics information for the user. The final feature of our application was that since the phone emulator doesn’t have an accelerometer, we wired the emulator up to a Wii controller allowing you to steer the robot with the accelerometer in it.
All in all it was a great weekend and I cannot wait till next time. Stay tuned, I have a bit of clean up to do in the code then I will be sure to post it also.
Remember the old Word Perfect days, when we had that paper glued to our keyboard telling us what the function keys did. Well with VS 2010 there are lots of great shortcuts. Zain our local DE has a good blog series on these tips (http://blogs.msdn.com/b/zainnab/), but it is helpful to have a list. Enter the Key Binding charts. You might have been lucky enough to get one from the languages team, but if not, you can print one out (http://blogs.msdn.com/b/lisa/archive/2010/04/16/vs-2010-keyboard-shortcut-posters-now-available-for-vb-c-f-c.aspx).
My only question is should we read something into the pictures? F# a young attractive woman, C# a middle aged guy with some goofy grin, and VB and older gentleman. hmm, what are they trying to say. . . .

So today I needed to cross reference some stuff in a text file with some stuff in a db. No big deal. Had about 200 unique values to lookup a few pieces of info out of a larger table in a db. The target table had about a half million rows in it, but was indexed on this particular column I needed to lookup on so it seemed like it should be no big deal. I have found myself using LINQPad more and more for little ad-hoc stuff like this.
Anyway, I was prepared to do something similar to this:
var list =
from lines in File.ReadAllLines(@"c:\myfile.txt").Distinct()
join c in MyTable on lines equals c.MyTable_ID
select c;
The problem with this is it grabs the entire table back and joins it. That's not really what I want and not optimal. If you look at the sql generated it should have one select that grabs the entire table.
However you can do something like this:
var list =
from lines in File.ReadAllLines(@"c:\myfile.txt").Distinct()
select
(
from c in MyTable.Where (cd => cd.MyTable_ID == lines)
select
new {
c.field1,c.field2,c.field3
}
).SingleOrDefault();
Now this query will generate a bunch of separate queries, each will be a query for the fields you request with just the single id you asked for. This will also give you a null record for non lookups, so you could figure out a way to handle it. Or at least see the empty lookups. This might be what you want, but in my case, I wanted a single query. I was hoping to generate an 'IS IN' type tsql where statement. One single query. The query above *did* reduce my query time from 'OMFG this is never going to complete and people will hate me for hanging up the server' to about a minute or two.
In contrast, I settled on this statement:
var list = from c in MyTable.Where(cd =>
File.ReadAllLines(@"c:\myfile.txt").Distinct().Contains(cd.MyTable_ID))
select
new {c.field1,c.field2,c.field3};
This statement took about 10 seconds and produced the query I was looking for. A big parameterized dealio that passed in a bunch of stuff for a 'where xx in yyy' clause.
What was also interesting was where the text manipulation took place in the queries vs sql or in IL depending on how I structured the LINQ statement. When I concatenated field2 and 3 inside of the select new statement in the second statement, it created a subselect in each statement that concatenated the two and then filtered by the id, when I did it in the third statement, it didn't do anything with it in the sql and just did it on the client side.
I'm a huge fan of LINQ now after being a hater for quite a while for it being yet another tool to distance developers from SQL. I use it a lot for adhoc reporting stuff and a variety of analysis. I'm not sure if you would want to do something like this on a regular basis in a regular app, but not sure why not. I'd be skeptical about unattended logic crossing machine boundaries like this on a regular basis in a middle tier somewhere, but I sure do love the versatility for my purposes. You can easily do all this in vs, but I gotta give some mad mad props to the LINQPad guys for a really great product. The main point of this article should be that just because you are using LINQ doesn't mean you can't take some time and really analyze what you are doing to make sure you are doing things the right way. I have seen several articles and blog entries slamming various orms or data access methodologies. Generally, they all seem to do what they are supposed to do for the most part if you just use them correctly and pay attention to what you are doing.
[edit: scott hanselman blogged about this as well (although better) so here's a link to that too =P]
Issue:
A client was experiencing very strange behavior following an upgrade from MOSS 2007 to SharePoint 2010 Server. In a nutshell some documents such as Word (.doc and .docx) would open while others such as Excel (.xls and xlsx) and PDF documents would not open.
Note: By open I mean when clicking on an Excel document, stored within a document library, it would not open in Excel installed on Windows 7, Vista, XP, etc.
Furthermore, the file type icons that normally display next to familiar documents such as Excel were missing and a missing image red x was displayed.
Thoughts:
The behavior of unrecognized File Types and missing document icons seemed to indicate an issue with the docIcon.xml configuration which is commonly located here: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML.
However, after inspecting this file on each server I could find nothing apparently wrong. Finally, one last tedious inspection revealed the issue. Following the upgrade we had to reconfigure the Adobe PDF IFilter which meant adding the following key to the docIcon.xml file:
<Mapping Key="pdf" Value="pdficon_small.gif" />
After looking at this entry more closely I noticed that the double quotations marks looked italicized “. This meant the configuration contain extra characters and was most likely edit with an editor like word pad instead of note pad.
Tip: Never use Word Pad to edit configuration files because it will add additional characters and likely corrupt the configuration file.
Solution:
I removed the unsupported double quotes and replaced them with unformatted double quotes. Viola, we could now open Excel and PDF Files again! Even better the cute little document type icons came back! :)
Further Explanation:
The reason the Excel Documents types became unavailable is because these document type mappings were located after the pdf file mapping within the docIcon.xml. Essential the invalid PDF entry broke all entries below it.
Hope this helps someone else!!!
So I was writing a really simple EF web method today. It just checked for the presence of two values in a table and would return true or false.
[WebMethod]
public
bool weird(long l, string s)
{
using (someEntities db = new
someEntities())
return db.things.SingleOrDefault(x => x.s == s && x.l == l.ToString()) != null;
}
The code above gives me the following error:
System.NotSupportedException: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression
This error gets thrown on the l.ToString(). It apparently has to do with LINQ expressions being evaluated somewhere else other than where it is built. Makes sense since ToString() could be anything as far as LINQ is concerned. I would think that things like string and int would be kinda handled, but hey, it's no biggy.Very simple work around, you just have to actually pass it a string in your LINQ expression like so just make a string and pass it in like so:
[WebMethod]
public
bool canAccessCustomer(long l, string s)
{
string sl = l.ToString();
using (someEntities db = new
someEntities())
return db.things.SingleOrDefault(x => x.s == s && x.l == sl) != null;
}
One could argue about taking in a long that is stored as a string and why it's not a long or some equivalent number in the db, but sometimes things are the way they are. =P
I found a couple of different pages referencing this one, but this seemed to be the best although it had a bunch of other 'solutions' other than simply passing a string in instead of running the function in your LINQ query which seemed the simplest to me.
So this apparently isn't supported, but I just thought I would jot down some notes about how to get it working. It is really not that hard as long as you don't mind installing SQLCE on your IIS server. I am still working on how to distribute the SQLCE files with the application.
I have a very small set of data that is mostly read and so I wanted to just dump it on a web server and not have a sql server. SQLCE seemed perfect for this although apparently that's not a use it's currently designed for. Here are some links I had open while I was working on this:
there are like a billion other links. I simply setup the db in a project where sqlce was allowed, and then copied the classes into the other project. A little connection string massaging and it worked fine.
Anyway, none of that is new/original, I couldn't find anything really current regarding how to get the sqlce dataprovider working on iis. There were a lot of references to machine.config and web.config/app.config fixes to put the provider in there etc. None of these worked for me. What did work was:
- Turning on the feature. I guess it is disabled by default. I simply added a line in the global.asax application start.
protected
void Application_Start(object sender, EventArgs e)
{
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
}
- Next, I (insert a long time of fiddling with the approaches above to get it to work but didn't) simply installed the sqlce runtime. I downloaded it from http://www.microsoft.com/downloads/details.aspx?familyid=E497988A-C93A-404C-B161-3A0B323DCE24&displaylang=en and installed the 32bit version. I am running .net 4.0, vs2010, windows server 2003 r2.
Hopefully I can find a way to distribute the SQLCE dlls with the app and it will just work since doing this install defeats one of my purposes which was to just simply be able to distribute a tiny set of data along with a simple access/manage set of services and not have to do any dependency installs. I have to say I think it's pretty stupid not to allow this to just work or to provide any clear instruction on microsoft's part. The realistic option for a normal person (and even for me) is to just install sqlite or do something else. I don't need full gui tool interoperability and I don't mind the hoops I have to jump through to get the classes setup etc, but I do wish if I had a project, any project, with a reference to that data provider that it would deploy whatever was/is needed easily. I'm sure there *is* a way to get it to work, but I haven't been able to find it. C'mon MS, toss me a token document that says 'if you want to use sqlce with anything, deploy these dlls, and do this in your solution and it'll work anywhere.' Or at least tell me where the data provider is weirded out on iis so I can fix it. I thought I was set when I found the info in step 1 above, but nope =P