by community-syndication | Aug 11, 2006 | BizTalk Community Blogs via Syndication
_______________________________________
From: sandusergiu1984@….com [mailto:sandusergiu1984@….com]
Sent: Fri 8/11/2006 9:20 AM
To: Eldar Musayev
Subject: (Random Thoughts and Hints on Software Development) : C# Code
I thought how can I write a program in C# that searches a SQL Server database and outputs the results to the user? and couldn’t give me please some ideas, or a fragment of code? Thanks a lot.
———————————-
This message was generated from a contact form at: http://blogs.msdn.com/eldar/default.aspx
Here it is. First, file Class1.cs (that’s a test driver):
using System;
namespace GetData
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(“Starting…”);
MyDataReader.InsertRow(73,”%u0413%u043f%u0444%u0433%u043f%u0444″);
Console.WriteLine(“Insert is done.”);
MyDataReader.ReadMyData();
Console.WriteLine(“Press any key to continiue…”);
Console.ReadLine();
Console.WriteLine(“… done.”);
}
}
}
Now the actual class that gets to the database:
using System;
using System.Data.SqlClient;
namespace GetData
{
/// <summary>
///
/// </summary>
public class MyDataReader
{
public MyDataReader()
{
}
// SQLEXPRESS is used for
// the free SQL Express edition of SQL Server
private static String myConnectionString = “Database=sample;Server=MyMachine\\SQLEXPRESS;Integrated Security=SSPI;”;
public static void InsertRow(int id, string str)
{
try
{
SqlConnection myConnection = new SqlConnection(myConnectionString);
string myInsertQuery = “INSERT INTO SampleTable (id, str) Values(‘”+id.ToString()+”‘, ‘”+str+”‘)”;
SqlCommand myCommand = new SqlCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
public static void ReadMyData()
{
string mySelectQuery = “SELECT id, str FROM SampleTable”;
SqlConnection myConnection = new SqlConnection(myConnectionString);
SqlCommand myCommand = new SqlCommand(mySelectQuery,myConnection);
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();
try
{
while (myReader.Read())
{
Console.WriteLine(myReader.GetInt32(0) + “, ” + myReader.GetString(1));
}
}
finally
{
// always call Close when done reading.
myReader.Close();
// always call Close when done reading.
myConnection.Close();
}
}
}
}
What you want is ReadMyData() method. Drop both files into the command-line C# program project in Visual Studio (Class1.cs instead of Class1.cs generated by Visual Studio), put the name of you machine into the connect string (and name of SQL Server instance too), compile, run. You are done. Of course, you need SQL Server installed, database sample, and table SampleTable with two fields – “id” and “str” in it.. You can use SQL Server on another machine, but see that it is configured to accept connections from non-local machine and use Windows authentications (that’s what SSPI stands fro in the connection string).
Good luck!
by community-syndication | Aug 11, 2006 | BizTalk Community Blogs via Syndication
I had to set this up recently, in both VS2005 and VS2003. It’s working great! Here is a great article with setup instructions…
http://alinconstantin.homeip.net/webdocs/scc/VSS_Internet.htm
by community-syndication | Aug 11, 2006 | BizTalk Community Blogs via Syndication
I received my Architects Journal this week (issue #8) and I read an interesting article entitled “Data Replication as an Enterprise SOA Anti-pattern”. (If you don’t already subscribe to the journal, I’d recommend it it’s a free quarterly publication focused on architectural issues and it is available here
The article spends time looking how it can quite often be a costly (and therefore a mistake) to implement a data replication anti-pattern within an enterprise and it also spends a bit of time looking at cases where it does make sense to use this anti-pattern.
While I was reading this, my mind immediately turned towards BizTalk (of course!) and I recognized two great BizTalk discussions that could be spawned from the ideas discussed in the article.
The first thing I thought about was how BizTalk is perfectly suited to handle both of these architectures. No matter which architecture you need to adopt, BizTalk makes it quick and easy to do.
The data replication anti-pattern calls for data to be synchronized from a master database out to child databases that power your other line of business applications. (I’m not going to get into the debate of whether or not this is a good architectural choice, that argument has already been covered in the article! J) Let’s just go with the assumption that you’ve done your homework and you know that for your situation, data replication is right for you. BizTalk and its data adapters will allow you to setup and implement this architecture quickly and at a very low cost. The following image outlines this solution.
In this architecture, BizTalk uses its SQL adapter to pull updated records from the master database in near real-time and then pushes them out to a set of other database and applications through other adapters. The internal BizTalk engine could even perform some data transformations and manipulation along the way if we needed. All in all, it is a very simple architecture to implement using the BizTalk.
Now let’s step back and say that instead of data replication, you decided to adopt a Services Oriented Architecture instead. BizTalk’s SQL adapter, SOAP Adapter and Web Services Wizard make this a very easy solution to implement as well.
So that’s great, but those were fairly simple architectures. What really becomes interesting is when we stop and realize that in the real world, we can’t always make architectural decisions in a bubble. We almost never get a one size fits all solution and we often find that we need many different solutions working together to meet all of our requirements. You might very likely find that what you really require is a hybrid solution, where some of your applications use data replication and some you applications leverage your SOA strategy. BizTalk can again be leveraged to power this hybrid architecture.
Stop and think about this for a second. In the past, developers often had to design, build, deploy and maintain projects that used multiple different technologies in order to support all of an organization’s integration requirements. With BizTalk you don’t have to do this! You’ve got one product that can leverage centrally to meet multiple integration requirements!
It is this extensive nature that I believe is the most valuable aspect of BizTalk when compared to so many of the other integration products available. BizTalk is not a point solution. It truly is a platform that can be used to deploy the solution(s) that you need. Many other integration products extol the virtues of a single architecture. I believe that these products fairly to give you the power to determine the solution that you need. They just don’t offer you the flexibility to be able to implement the solution that is best suited for you. It is your architects and developers (the people that can truly understand your business and your business needs) that should be deciding on architecture that you deploy, not your integration product.
That last thought leads nicely into second topic that came to mind while I was reading this article. BizTalk really is the Swiss army knife of the integration world. It gives you a ton of tools that you can use in many different ways to implement many different integration solutions. While that gives you the advantage of being able to implement the solution that you need, it can lead to problems if you don’t have the experienced and knowledgeable people implementing those solutions for you. The article in the journal referred to data-replication as an anti-pattern. An anti-pattern basically refers to a solution that appears to have benefits, but will ultimately generate negative consequences if followed. The danger with BizTalk is that it is often just as easy to implement an anti-pattern as it is to implement a quality pattern. It allows you to power a wide range of architectures and implement many different patterns, but it can’t tell you which one will be best suited for your requirements. An inexperienced architect can use the various elements of BizTalk to create a solution that performs poorly, is difficult to maintain and is ultimate doomed to fail. An experienced architect and knowledgeable BizTalk developer can create a great solution that is highly available, easily scalable, performs incredibly fast, is reliably and is easy to maintain.
Ultimately, BizTalk is a very extensive platform that is going to give you the widest range of options possible when you are laying out your integration solutions. However it relies on your architects and developers to make sure that those solutions are great ones. BizTalk really is a tool that believes in the people “People Ready Process”! (If you haven’t heard about People Ready processes and how we believe that your employees are you companies most important asset, then check out this – The People Ready Business
Cheers and keep on BizTalking
by community-syndication | Aug 11, 2006 | BizTalk Community Blogs via Syndication
I’ve decide to update and repost several BizTalk development tips after getting quite a few email questions on mapping. Please keep those questions coming!
One issue that always comes up when creating output nodes conditionally is how to determine the position or LineNumber of the nodes conditionally created. Normally, this is done by connecting the Iteration functoid (which uses the XSLT position() function to determine which input node is currently being processed) from the inbound looping structure to a field in the outbound schema. This will create a LineNumber value for each conditionally created node such as 1, 4, 7, 10, etc. Unfortunately, what we want is the position() of the output node being conditionally created so that our LineNumber values are in sequence such as 1, 2, 3, 4, etc.
Figure 1. Counting Line Items
Once again, the answer is to turn to the Scripting functoid and write some simple Inline C# code to accomplish this. One thing to note is that Inline scripts are also useful for declaring global variables that can be accessed from any number of scripts in your map. In the map shown above, I used this idea to create a System.Text.StringBuilder object called LineItem that would act as a text counter. Since the LineItem variable is global, it is only updated when the CurrentLine method is called.
Figure 2. Inline C#
This script uses the StringBuilder.Append method to add one character to the LineItem object each time an output node is conditionally created and uses the StringBuilder.Length property to return the LineNumber value in the outbound document.
I used to think that there were more elegant solutions available but after using this for over two years, I’m not so sure. This was a quick and easy way to solve the problem and shows just how flexible mapping can be in BizTalk Server 2006.
Technorati Tags: BizTalk Server, BizTalk
by community-syndication | Aug 10, 2006 | BizTalk Community Blogs via Syndication
One of my readers asked me the other day about client(proxy) extensibility points on Windows Communication Foundation (WCF). Conceptually there a number of scenarios in which makes sense to extend proxy functionalities.
- Custom Message Validation. A user may want to enforce that a message is valid for a certain schema. This can be done by implementing the IClientMessageInspector interface and assigning the implementation to the MessageInspectors property.
- Custom Message Logging. A user may want to inspect and log some set of application messages that flow through an endpoint. This can also be accomplished with the message interceptor interfaces.
- Custom Message Transformations. Rather than modifying application code, the user may want to apply certain transformations to the message in the runtime (for example, for versioning). This can be accomplished, again, with the message interceptor interfaces.
- Custom Data Model. A user may want to have a data or serialization model other than those supported by default in WCF (namely, XmlFormatter, XmlSerializer, and raw Messages). This can be done by implementing the message formatter interfaces.
- Custom Parameter Validation. A user may want to enforce that typed parameters are valid (as opposed to XML). This can be done using the parameter inspector interfaces.
As part of our daily interaction with customers we (TwoConnect) had developed different demos to illustrate these features.
On the WCF model there are two main client extension classes ClientRuntime and ClientOperation. Both classes are intended to extend the service proxy. However ClientRuntime extends the proxy at the contract level while ClientOperation works at operation level. In order to insert extension points in both cases you should use behaviors. Obviously ClientRuntime provides a broader set of options given that extension points can be inserted in endpoint, contract, operation or service behaviors respectively. On the other hand extension points for ClientOperation are typically represented by operation behaviors.
The following example shows how to create a custom endpoint behavior and add a custom message inspector to it.
|
public class SampleCustomBehavior: IEndpointBehavior
{
public void AddBindingParameters(ServiceEndpoint serviceEndpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters)
{ }
public void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, System.ServiceModel.Dispatcher.ClientRuntime behavior)
{
//Add the inspector
behavior.MessageInspectors.Add(new CustomMessageInspector());
}
public void ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher)
{ }
public void Validate(ServiceEndpoint serviceEndpoint)
{ }
}
|
CustomMessageInspector class declaration looks like the following
|
public class CustomMessageInspector : IClientMessageInspector
{
#region IClientMessageInspector Members
public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
{
}
public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
{
Console.WriteLine(request.ToString());
return null;
}
#endregion
}
|
Finally the following code illustrates how to add the behavior to the service’s proxy
|
MyServiceClient proxy = new MyServiceClient();
proxy.Endpoint.Behaviors.Add(new SampleCustomBehavior());
|
by community-syndication | Aug 10, 2006 | BizTalk Community Blogs via Syndication
Sometimes You Have to Write Some Code!
That’s right. You heard me. Sometimes you have to roll up your sleeves and write some code. Even using Commerce Server 2007!
I’ve been pretty amazed how full featured and complete Commerce Server 2007 is and how little custom code I had to write to get my e-commerce site up and running. But every once in a while I run into a scenario that the product just doesn’t cover very well. One such “pain point” is how to display a list of a user’s or organization’s shipping addresses without including the billing address.
In our B2B scenario the customer’s billing address and customer ID “define” the customer in the back-end ERP system. This means we really don’t want to allow the customer to edit this address on the site, but we DO want to allow the customer to add, change and delete his shipping addresses. The Commerce Server Profiles subsystem doesn’t cover this scenario as none of the standard methods will return only the shipping addresses.
So we dug under the covers (a little) and wrote a simple method which returns a DataSet containing only shipping addresses from the <sitename>_profiles database.
Nothing fancy, just some C# code which calls a stored procedure as shown below. The “magic” is in setting up the Address profiles including the Address Type.
The result is a standard DataSet which can be bound to any number of ASP.NET server controls such as the GridView shown here.
The C# code resides in a helper class in the site’s App_Code folder and the custom stored procedure resides in the <sitename>_profiles database. Typical ASP.NET 2.0 stuff applied to a scenario Commerce Server just doesn’t cover (at least not yet).
Take Away: Not all your e-commerce needs will be covered by the subsystems included with Commerce Server 2007, but combined with C#, T-SQL and ASP.NET 2.0 there’s almost nothing you can’t create! Use Your Imagination…
Technorati Tags: Commerce Server
by community-syndication | Aug 10, 2006 | BizTalk Community Blogs via Syndication
For all of you in the press that still doubt Microsoft’s commitment to e-commerce applications and Commerce Server, please take note!
Commerce Server Roadmap
“With Commerce Server 2007 we feel we have delivered an outstanding product for enterprise customers and know that Commerce Server 2007 is capable of running the most demanding e-commerce applications in the world. Next, our focus is on expanding the audiences with a complimentary release to hit the targets not addressed directly by Commerce Serve r2007; specifically enabling Small/Medium businesses to affordably create e-commerce solutions. This means thinking hard about developer productivity, customization, designability, hostability, and more. Building this core-commerce infrastructure is the immediate next step and will bring significant evolution in user experience across all audiences to greatly simplify the complex task of e-commerce development, deployment, and management.” – Taken from the Commerce Server Roadmap
Technorati Tags: Commerce Server
by community-syndication | Aug 10, 2006 | BizTalk Community Blogs via Syndication
I’m always needing these settings, so I’ve got them.
“Where’s that (more) complete config file when you need it??” – look no further.
I’ve also included some BTS process memory throttling options as well – due to a recent
Out of Memory Exception I resolved.
———-
<?xml version=”1.0″ ?>
<configuration>
<configSections>
<section name=”xlangs” type=”Microsoft.XLANGs.BizTalk.CrossProcess.XmlSerializationConfigurationSectionHandler,
Microsoft.XLANGs.BizTalk.CrossProcess” />
</configSections>
<!–
these settings are for BTS making HTTP/SOAP calls out, 2 concurrent connections is
the default.
This should be in EVERY system where
BTS is calling WebServices –>
<system.net>
<connectionManagement>
<add address=”*” maxconnection=”40″/>
</connectionManagement>
</system.net>
<runtime>
<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>
<probing privatePath=”BizTalk
Assemblies;Developer Tools;Tracking;Tracking\interop” />
</assemblyBinding>
</runtime>
<system.runtime.remoting>
<channelSinkProviders>
<serverProviders>
<provider id=”sspi” type=”Microsoft.BizTalk.XLANGs.BTXEngine.SecurityServerChannelSinkProvider,Microsoft.XLANGs.BizTalk.Engine” securityPackage=”ntlm” authenticationLevel=”packetPrivacy” />
</serverProviders>
</channelSinkProviders>
<application>
<channels>
<channel ref=”tcp” port=”0″ name=””>
<serverProviders>
<provider ref=”sspi” />
<formatter ref=”binary” typeFilterLevel=”Full”/>
</serverProviders>
</channel>
</channels>
</application>
</system.runtime.remoting>
<appSettings>
<add key=”Key1″ value=”Hello,
World!” />
</appSettings>
<xlangs>
<Configuration><!—
MaxThreshold – “Max time in memory an Orch will reside before dehydrat” MinThreshold
– “Min time” —>
<Dehydration MaxThreshold=”1800″ MinThreshold=”1″ ConstantThreshold=”-1″>
<!—
Currently, virtual memory can become a bottleneck on 32-bit machines due to unmanaged
heap fragmentation, so you should throttle by this resource as well. —>
<VirtualMemoryThrottlingCriteria OptimalUsage=”900″%u00c2” MaximalUsage=”1300″ IsActive=”true” />
<!—
This is a useful criterion for throttling, but appropriate values depend on whether
the box is being shared among servers. If the machine has a lot of RAM and is not
being shared with other functions, then these values can be significantly increased.Optimal
and maximal usage are in MB.–>
<PrivateMemoryThrottlingCriteria OptimalUsage=”50″ MaximalUsage=”350″ IsActive=”true” />
</Dehydration>
<Debugging ValidateSchemas=”true” ValidateAssemblies=”true” ExtendedLogging=”true” ValidateCorrelations=”false” />
<AppDomains AssembliesPerDomain=”10″>
<AppDomainSpecs>
<AppDomainSpec Name=”DemoDomain” SecondsIdleBeforeShutdown=”-1″ SecondsEmptyBeforeShutdown=”12000″ />
</AppDomainSpecs>
<ExactAssignmentRules>
<ExactAssignmentRule AssemblyName=”Configuration,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=3a7d0586c62e754b” AppDomainName=”DemoDomain” />
</ExactAssignmentRules>
</AppDomains>
</Configuration>
</xlangs>
</configuration>
by community-syndication | Aug 10, 2006 | BizTalk Community Blogs via Syndication
I think its time to resurrect this article for a bit. I wrote this back in October of 2004 with BizTalk Server 2004 in mind, but quite a bit of it is still relevant for BizTalk Server 2006. It covers a lot of the common problems in a platform installation. Although much improved over 2004, there are still problems inherent with the existence of a product like BizTalk Server 2006 and the complex stack it rests on.
- http://blogs.msdn.com/luke/articles/241024.aspx
by community-syndication | Aug 10, 2006 | BizTalk Community Blogs via Syndication
Creates compiled help files for a given BTS 2006 installation. This tool can be run on an ad-hoc basis using the UI or from the command line as a post build/deploy task to create a compiled help file describing a BTS 2006 installation.