SSMS, can't drop table after design modifications Saturday, October 3, 2009



If you have just installed SSMS (SQL Server Management Studio) 2008 you may not be able to save changes because SSMS does not permit table recreation. the solution is pretty easy.open Tools > Options > Designers and uncheck this option "Prevent saving changes that require table re-creation"

have a look the sreenshot:


LINQ To SQL CRUD and simple Update Sunday, July 12, 2009

Though Nhibernate shines on ORM world of .NET LINQ-To-SQL is faster when it comes to prototyping.

The big Mature Nhibernate has a solid session management code-base, also Burrow and Spring.Net have developed their own session management libraries for Nhibernate.
LINQ-To-SQL session management could be tricky especially with a state-less framework like ASP.NET so somehow you may find it better to create an instance every time you want to consume your database (Singleton pattern may not be the best answer here, please read Rick Strahl full article here) so basically the DataContext CRUD is all straight forward except the U part.

To Create an new entity you simply use the following code:


DbContext dbcontext = new DbContext(ConfigurationManager.ConnectionStrings[0].ConnectionString);
Request req = new Request();
req.Status = RequestStatus.PendingShipment;
req.UserId = Convert.ToInt32(signupUser.ProviderUserKey);
req.SubmittedOn = DateTime.Now;
dbcontext.Requests.InsertOnSubmit(req);
dbcontext.SubmitChanges();
dbcontext.Dispose();




to Delete a record :

DbContext dbcontext = new DbContext(ConfigurationManager.ConnectionStrings[0].ConnectionString);
Request req = dbcontext.Request.Single(r => r.id == requestId);
req.Status = RequestStatus.PendingShipment;
req.UserId = Convert.ToInt32(signupUser.ProviderUserKey);
req.SubmittedOn = DateTime.Now;
dbcontext.Requests.DeleteOnSubmit(req);
dbcontext.SubmitChanges();
dbcontext.Dispose();


and here comes the tricky Update:


DbContext dbContext = new DbContext(System.Configuration.ConfigurationManager.ConnectionStrings[0].ConnectionString);

dbContext.Requests.Attach(currentRequest);
dbContext.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, currentRequest);
dbContext.SubmitChanges();
dbContext.Dispose();




on updating your entities you don't need to reload the original entity of perform one-by-one property comparison, all you need is to Attach your entity and Refresh using KeepCurrentValues to keep unmodified items as is.

FedEx SOAP error : Schema validation failed for request Thursday, July 2, 2009

This issue is a bit tricky ! why does FedEx SOAP raises a Schema validation error ?

It seams that FedEx service is expecting you to perform a complete SOAP message including all elements even if you don't need on your service call.

Have a look on this C# code which performs a "valid" SOAP call :


PackageMovementInformationService svc = new PackageMovementInformationService();
var request = new PostalCodeInquiryRequest();
request.CarrierCode = CarrierCodeType.FDXE;
request.ClientDetail = new ClientDetail
{
AccountNumber = "ACCOUNT_NO",
Localization = new Localization
{
LanguageCode = "EN",
LocaleCode = "US-EN"
},
MeterNumber = "METER_NO"
};
request.CountryCode = "US";
request.PostalCode = "38017";
request.WebAuthenticationDetail = new WebAuthenticationDetail
{
UserCredential = new WebAuthenticationCredential
{
Key = "__KEY__",
Password = "_Password_"
}
};
request.Version = new VersionId ();
request.TransactionDetail = new TransactionDetail
{
CustomerTransactionId = "23",
Localization = new Localization { LocaleCode="US-EN", LanguageCode="EN" }
};

PostalCodeInquiryReply reply = svc.postalCodeInquiry(request);



This code didn't generate any validation errors because i simply did not leave any of PostalCodeInquiryRequest class members not instantiated.

if are using Ruby,Python or PHP just check you fill all the SOAP request elements.


UPDATE : for a comprehensive details of what elements are missing check an element named "detail" of the SOAP exception response.

runway or a road ? Monday, May 4, 2009



seems like Gibraltar people wanted an Airport so bad !














Windows, Python and Eric4 IDE Tuesday, February 10, 2009

Python is really fun ! mixing OOP with procedural programming is powerful and not a flaw in Python as always Ruby guys wanted to convince you ;)

Almost all Linux flavors include python but for windows you may want stuck with ActiveState ActivePython package which will setup python for you (PATH variable and registry entries) as will as a rich set of windows APIs backing your Python scripting for windows.

The IDE

The are plenty of Python Editors and IDEs. WingIDE is the Python's IntelliJ , the best but costs, so i picked Eric4. regardless the 90's web design of the project website Eric4 has numerous features including Integrated Python Debugger, coding folding, Auto-completion,error highlighting and much much more.

assuming you have already install ActivePython, getting Eric4 to work is straight-forward :

  1. Download the latest package from SourceForge project page.
  2. for compiling Eric4 you will need Microsoft VC++ redistributable from here.
  3. finally you'll need PyQt (Python binding for Qt Framework). simply install Riverbank preconfigured PyQt package which includes Qt runtime from here.

After downloading Eric4 archive go forward and extract it in you preferred location , lets pick c:/program files as the windows De facto. Install Microsoft VC++ and PyQt mentioned in step 1 & 2 and finally browse to Eric4 directory and type the following on you Command Line:

C:\Program Files\eric4-x.x.x> python install.py

That's it ! a batch file eric4.bat will be generated. feel free to to add a shortcut into your desktop or whatever place.


on the upcoming post i will show you how to set up a productive Django Development Environment using Eric4 and their django plugin, Till then :)

Intellij , increase Java's Memory Friday, February 6, 2009






It's common to get Out Of Memory exception when you run application or Debug application on Inellij, However that's not a bug ! you only need to increase JAVA memory settings.

The steps are as follows :

  1. go to "Run" menu the select "Edit Configurations"
  2. increase the memory of Java VM passing -Xmx512M parameter, see the screen shot below.




Enlight your blogger with SyntaxHighlighter 2.0 ! Wednesday, February 4, 2009






Syntax highlighting is essential for your blog posts with code snippets. The Just released SyntaxHighlighter 2.0 is a breeze to use and work with.
I will follow you on this post to successfully integrated SyntaxHighlighter 2.0 into your blogger without having to setup an external hosting.

Step 1:
Login into your Blogger go to the Layout tab and then to Edit HTML

Step 2:


browse your template and locate the <head> Tag

add the following javascript includes:



<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shCore.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushPlain.js' type='text/javascript' />
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushXml.js' type='text/javascript' />
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushCss.js' type='text/javascript' />
<script src='http://alexgorbatchev.com/pub/sh/2.0.278/scripts/shBrushJScript.js' type='text/javascript' />




Step 3:

Blogger does not accept <link> tags within the <head> , you need to manually copy&paste css to the <head> tag:
the css required are
http://alexgorbatchev.com/pub/sh/2.0.278/styles/shCore.css
and
http://alexgorbatchev.com/pub/sh/2.0.278/styles/shThemeDefault.css

Step 4:
add the following javascript into the head tag :

SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/2.0.278/scripts/clipboard.swf';
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.gutter = false;
SyntaxHighlighter.all();



Step 5:

You now need to wrap the text inside your pre tags which will later include the code snippets. unwakeable provide an excellent css snippet which resolves such issue in almost all modern browsers.

ok, back to the <head> tag , add the following style:

pre {
overflow-x: auto; /* Use horizontal scroller if needed; for Firefox 2, not needed in Firefox 3 */
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
/* width: 99%; */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}


That's it ! save you template and Start blogging with code snippets inside <pre> tags.



if you like it please consider donating , it's DonationWare anyways :)