Search This Blog

Wednesday, September 30, 2009

List constrainsts on a table

SELECT  sc.constid ConstraintID,
so.name TableName,
CASE WHEN sc.colid = 0 THEN '' ELSE s.name END ColumnName,
CASE
WHEN sc.Status & 32 > 0 then 'Table-level'
WHEN sc.Status & 16 > 0 then 'Column-level'
WHEN sc.Status & 5 > 0 then 'DEFAULT'
WHEN sc.Status & 4 > 0 then 'CHECK'
WHEN sc.Status & 3 > 0 then 'FOREIGN KEY'
WHEN sc.Status & 2 > 0 then 'UNIQUE KEY'
WHEN sc.Status & 1 > 0 then 'PRIMARY KEY'
END + ' constraint'
FROM sysconstraints sc
INNER JOIN sysobjects so ON so.id = sc.id AND so.xtype = 'u'
LEFT JOIN syscolumns s ON s.colid = sc.colid AND so.id = s.id

Saturday, September 26, 2009

Fun with Deserialization

More fun serialization, this time with deserialization.

Currently working on a .net project whose feature set will allow my to replace some older third party libraries used in a VB6 project that do not work properly under Vista 64bit edition.

Things that I have successfully completed:
  • Replaced Microsoft IE6 era Web browser control with a .net webbrowser control in a winform.
  • Replaced functionality of Microsoft Internet transfer control to download online files.
  • Successfully extended Google Picasa API and Blogger API to VB6 through COM interop type library
  • Successfully implemented binary serialization of Picasa and Blogger caching the data locally.
DRCWinformUI.DLL - COM Interop assembly exposing methods/events for use in VB6 project
PicasaBloggerUserControls.DLL - .net 2.0 framework

Now to the problem: Deserialization:

Implemented code to de-serialize objects, which works fine in .net test app, but fails over COM:
SerializationException: Cannot find assembly...

Found the following articles:
Excellent article from http://spazzarama.wordpress.com/ describing the exact same problem:

C# – BinaryFormatter.Deserialize is “Unable to find assembly”


Documentation for SerializationBinder Class

I must give props to a co-worker Tom G. who pointed me in the correct direction of properly resolving the assembly by name. A problem that was solved at work on another project.

Sunday, September 20, 2009

Query for Blog posts by date


FeedQuery query = new FeedQuery();
query.Uri = new Uri("http://www.blogger.com/feeds/" + blogId + "/posts/default");
query.MinPublication = new DateTime(2006, 1, 1);
query.MaxPublication = new DateTime(2007, 4, 12);
AtomFeed feed = service.Query(query);
foreach (AtomEntry entry in feed.Entries)
{
Console.WriteLine(" Entry Title: " + entry.Title.Text);
}

Saturday, September 5, 2009

Creating ActiveX control using C#

Get the VSS.net templates from http://www.codeproject.com/KB/vb-interop/VB6InteropToolkit2.aspx

Copy the project template zip file into your project templates folder (the default location is ...\My Documents\Visual Studio 2005\Templates\ProjectTemplates\Visual C#) and the item template zip file into your item templates folder (...\My Documents\Visual Studio 2005\Templates\ItemTemplates\Visual C#).


A backup of the files on skydrive

Wednesday, September 2, 2009

Fun with Binary Serialization

Articles to read...
How to serialize an object which is NOT marked as 'Serializable' using a surrogate.
C# Tutorial - Serialize Objects to a File
Serialization in C#
Object Serialization using C#

Sample code - will serialize class with child classes that are not explicitly serializable. (Work in progress though).

SurrogateSelector ss = new SurrogateSelector();
PicasaAlbumAccessorSurrogate aass = new PicasaAlbumAccessorSurrogate();
PicasaEntrySurrogate pess = new PicasaEntrySurrogate();
PicasaFeedSurrogate pfss = new PicasaFeedSurrogate();

ss.AddSurrogate(typeof(AlbumAccessor),
new StreamingContext(StreamingContextStates.All), aass);
ss.AddSurrogate(typeof(PicasaEntry),
new StreamingContext(StreamingContextStates.All), pess);
ss.AddSurrogate(typeof(PicasaFeed),
new StreamingContext(StreamingContextStates.All), pfss);

BinaryFormatter formatter = new BinaryFormatter();
string filename = string.Format("{0}\\album_{1}_{2}_{3}.dat",
System.Environment.CurrentDirectory, _accessor.AlbumAuthor,
_accessor.Name, _accessor.Id);
FileStream fs = new FileStream(filename, FileMode.Create);
formatter.SurrogateSelector = ss;
formatter.Serialize(fs, this);
fs.Close();

Tuesday, September 1, 2009

Load bcp with Bulk Insert

This is impossible using Google:

BULK INSERT database.dbo.table
FROM 'full_path_name.bcp'
WITH (
DATAFILETYPE = 'native',
KEEPIDENTITY
)

Make sure Full path name is in single quotes.
http://msdn.microsoft.com/en-us/library/ms188365.aspx