Software Development : A dizzy job...keeping abreast and being competitive is a 24X7 involvement
Mar 22, 2007
Mar 15, 2007
Enabling the CLR in the Sql Server 2005
You will need to enable the CLR.
Here are the commands that I used to enable the CLR.
-----------------------------------------------------------
EXEC sp_configure 'show advanced options' , '1';
go
reconfigure;
go
EXEC sp_configure 'clr enabled' , '1'
go
reconfigure;
-----------------------------------------------------------
Mar 14, 2007
Connecting to Sql Server 2005 from c# winforms An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005
Q: I get the following error when trying to connect:"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
I enabled Named Pipes but left TCP/IP disabled because this is a localhost connection on the same computer.
Here is the portion of the code I am using to connect:
string dbCString = "Persist Security Info=False;Integrated Security=true;Trusted_Connection=true;
Initial Catalog=MxData;server=(local)";
SqlConnection ThisConnection = new SqlConnection(dbCString);ThisConnection.Open();
After a lot of research, here's the answer.
The connection string should read as follows:
"Server=.\\SQLEXPRESS;Initial Catalog=MxData;Integrated Security=SSPI";
Note that you need a dot followed by TWO left slashes in your server name.
BTW, Initial Catalog is whatever database you want to use.
Mar 4, 2007
Send Mail Using Lotus Notes
'This public sub will send a mail and attachment if neccessary to the recipient including the body text.
'Requires that notes client is installed on the system.
Public Sub SendNotesMail(Subject As String, attachment As String, recipient As String, bodytext As String, saveit As Boolean)
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = recipient
MailDoc.Subject = Subject
MailDoc.Body = bodytext
MailDoc.SAVEMESSAGEONSEND = saveit
'Set up the embedded object and attachment and attach it
If attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", attachment, "Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
Adding controls to ASP.NET page at runtime
We add control dynamically, attach event handler to it's event and nothing happened. What is wrong?
It is common question asked again and again. Adding controls to ASP.NET WebForm at runtime is a simple task:
private void Page_Load(object sender, System.EventArgs e)
{
Button newButton = new Button();
newButton.Text = "New Button";
newButton.ID = "newButton";
newButton.Click += new System.EventHandler(this.newButton_Click);
WebUserControl1 newUserControl = (WebUserControl1)LoadControl("WebUserControl1.ascx");
newUserControl.ID = "newUserControl";
this.PlaceHolder.Add(newUserControl);
this.PlaceHolder.Add(newButton);
}
Problem
Now let's raise a bet little. What if we want to add new control as a result of some user action (button click for example)?
We are moving the same code from Page_Load to Button_Click event and… Here troubles begin. Our controls will show as expected, but only first time.
Any postback will reset page to its original state. Dynamically created controls will be unable to fire any event.
What is happening here? The answer is simple.
Page class is stateless. It is destroyed after rendering. Page recreates child controls collection,
based on tags in aspx file, then postback data can be handled and event handlers attached (in OnInit event).
Controls we just created dynamically do not exist in aspx file; page has no knowledge about them.
Solution
Solution is also simple. We have to recreate controls on load stage of page lifecycle. After it's done, each control can handle his postback data,
retrieve saved viewstate, raise events etc.
Now code skeleton will look like this:
private void Page_Load(object sender, System.EventArgs e)
{
RecreatePersistedControls();
}
private void Button_Click(object sender, System.EventArgs e)
{
CreateControl("newControl");
PersistControl("newControl");
}
private void RecreatePersistedControls()
{
// Call CreateControl for each persisted control
}
private void CreateControl(string id)
{
// Create controll with specified id,
// add it to controls collection, attach event handlers
}
private void PersistControl(string id)
{
// Persist specified id (in session for example)
}
See fully functional example at Code Project
Dec 6, 2006
Changing the default Source Control Provider in VS.Net
In the registry there is are two keys
1) HKEY_LOCAL_MACHINE\SOFTWARE\SourceCodeControlProvider
and
2) HKEY_LOCAL_MACHINE\SOFTWARE\SourceCodeControlProvider\Inst alledSCCProviders
In the key #2 you should see two entries:
ClearCase=Software\Atria\ClearCase and Microsoft Visual SourceSafe=Software\Microsoft\SourceSafe
What you need to do is delete the "ClearCase" value, so that only the "Microsoft Visual SourceSafe" is left.
In key #1, make sure that the ProviderRegKey is set to "Software\Microsoft\Visual SourceSafe".
Alternatively, just register the ssscc.dll in your C:\Program Files\Microsoft Visual Studio\VSS\win32 with the regsvr32.exe tool and the Default Source Control Provider will change back to VSS.
And thats it!
Nov 5, 2006
ASP.NET Side-by-Side Execution of .NET Framework 1.0 and 1.1
In ASP.NET, applications are said to be running side by side when they are installed on the same computer, but use different versions of the .NET Framework. The following topic describes how to configure ASP.NET applications for side-by-side execution and provides detailed steps to:
Traditionally, when a component or application is updated on a computer, the older version is removed and replaced with the newer version. If the new version is not compatible with the previous version, this usually breaks other applications that use the component or application. The .NET Framework provides support for side-by-side execution, which allows multiple versions of an assembly or application to be installed on the same computer at the same time. Because multiple versions can be installed simultaneously, managed applications can select which version to use without affecting applications that use a different version.
By default, during the installation of the .NET Framework version 1.1, all existing ASP.NET applications are automatically reconfigured to use the latest version of the .NET Framework. If you do not want your ASP.NET applications to default to .NET Framework 1.1, click here to learn how to prevent this during installation.
If you update your Web server to .NET Framework 1.1 and want one or more Web applications to run .NET Framework 1.0, you need to update the Internet Information Services (IIS) Script Map. The script mapping is the mechanism to map the .aspx file extension for a specific Web application to a version of the .NET Framework. Click here to learn how to map a Web application to a specific version of the .NET Framework.
You can use the Internet Information Manger or the ASP.NET IIS Registration Tool (Aspnet_regiis.exe) to find which .NET Framework version is running a particular Web application. Click here to learn how to find the version of the .NET Framework that a Web site is using.
One import consideration when migrating to .NET Framework 1.1 is that each version of the .NET Framework uses its own Machine.config file. As a result, if a Web administrator has made changes to the Machine.config file, those changes must be migrated to the .NET Framework 1.1 Machine.config file.
Maintaining your Web application’s mapping to .NET Framework 1.0 during installation
By default, all existing ASP.NET applications are automatically reconfigured during installation to use the newer version of the .NET Framework. Using the newer version of the .NET Framework, applications can take full advantage of improvements and new features included in the new release. At the same time, the Web administrator, who might want granular control over which applications are updated, can prevent the automatic remapping of all existing ASP.NET applications during installation of the .NET Framework.
To prevent the automatic remapping of the entire ASP.NET application to the newer version of the .NET Framework, the Web administrator can use the /noaspupgrade command-line option with the Dotnetfx.exe setup program.
To prevent total remapping of ASP.NET application to newer version- Go to Start.
- Click on run.
- Type cmd.
- Click OK.
- From the command prompt, type the following line to start the installation of the .NET Framework: Dotnetfx.exe /c:"install /noaspupgrade”.
- Click Yes in the Microsoft .NET Framework 1.1 Setup. This will start the setup process of the .NET Framework 1.1.
Map a Web application to a specific version of the .NET Framework
Each version of the .NET Framework includes a version of the ASP.NET IIS Registration Tool (Aspnet_regiis.exe). This tool enables administrators to specify that a Web application be run under a particular version of the .NET Framework. This is referred to as mapping a Web application to a version of the .NET Framework. Administrators must select the Aspnet_regiis.exe that corresponds to the version of the .NET Framework that will be associated with the Web application. For example, an administrator who wants to specify that a Web site use .NET Framework 1.1 must use the Aspnet_regiis.exe that comes with .NET Framework 1.1.
The Aspnet_regiis.exe for version 1.0 is located at:
- C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\aspnet_regiis
The Aspnet_regiis.exe for version 1,1 is located at:
- C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis
The Aspnet_regiis.exe provides two options for script mapping a Web application:
- –s sets the script map in the path and in its child directories.
- –sn sets the script map in the path only.
The path defines the Web application IIS metadata path, which is defined in the form of W3SVC/ROOT/{WebSiteNumber}/{Application_Name}. For example, for a Web application called Portal located under the default Web site, the metabase path is W3SVC/1/ROOT/Portal.
Note You can also use a tool called the Metabase Editor to get the metabase path. You can download this tool from the Microsoft Support site at http://support.microsoft.com/default.aspx?scid=kb;en-us;232068.
- Run Aspnet_regiis.exe –s W3SVC/1/ROOT/Portal to update the portal IIS script map and its subapplication.
- Run Aspnet_regiis.exe –sn W3SVC/1/ROOT/Portal to update the portal IIS script map, without affecting applications in the portal’s subdirectories.
Find the .NET Framework version that a Web application is using
An administrator can use the Internet Service Manager to find which version of the .NET Framework runs a Web site. Different operating system versions launch the Internet Service Manager differently. To start the service manager, follow the steps listed below.
- Go to Start.
- Click on run.
- Type inetmgr.
- From the Internet Service Manager, select the Web application whose version of the .NET Framework you want to know.
- Right-click on the Web application, and click on Properties.
- From the Property window, select Configuration.
- From the application mapping table, select .aspx, and click Edit.
- 8. From the Executable text box, look at the version directory by scrolling. If the version directory is v.1.1.4322, the application is mapped to .NET Framework 1.1. Conversely, if the version directory is v1.0.3705, the application is mapped to .NET Framework 1.0.
Sep 12, 2006
Create a List / combbopx in a Excel worksheet
Drop-Down list example allows a user to select a day of the week
Steps:
Select the cell or range of cells that is to contain the dropdown list box.
This may be either a single cell or a larger range
Click Data, then Validation.
Click the Settings tab (if necessary)
Under Allow, click the down arrow and select List.
Using the Source box either enter the range (A-direct list) or refer to a range (B-referenced list).
A - Type your list into the Source box. Separate items with commas with no spaces in between.
B - From within the Source Box either click and drag to select a range or type = and enter the range coordinates.
Notes
If a user tries to manually enter anything other than these values, a stop message appears and will not allow the cell to keep the invalid entry. The only options for the user will be to Retry or Cancel.
It will be possible to make valid entries (i.e., MON, TUE, WED, etc.) manually in a cell to which this validation setting has been applied; a user is not required to actually select these values from the list.
Drop-down lists (or manual entry) is not case sensitive; Wed, WED, wed, etc are all treated the same.