ctor + tab + tab
Auto Macro Code Snippet for CLASS constructor in Visual Studio
class Employee
// Contructor
{
public Employ()
{
// Default property for FirstName
FirstName = "" // Better than NULL which is the default
}
}
This blog shares my journey as a software engineer, along with personal reviews and life experiences I’ve gained along the way. “I have not failed. I've just found 10,000 ways that won't work.” — Thomas Edison. If you enjoy my content, please support it by clicking on ads (free for you, big help for me!) or by buying me a coffee on Ko-fi. Thank you!
Saturday, June 01, 2013
Wednesday, May 08, 2013
Logging Exception to a text file when catch(Exception e)
catch (Exception e) { StringBuilder sb2 = new StringBuilder(); sb2.Append("Exception Date/Time: " + DateTime.Now); sb2.Append(System.Environment.NewLine); sb2.Append(System.Environment.NewLine); sb2.Append("Exception Message: " + e.Message); sb2.Append(System.Environment.NewLine); sb2.Append(System.Environment.NewLine); sb2.Append("Stack Trace:" + e.StackTrace); sb2.Append(System.Environment.NewLine); sb2.Append(System.Environment.NewLine); sb2.Append("Inner Exception:" + e.InnerException); sb2.Append(System.Environment.NewLine); sb2.Append(System.Environment.NewLine); sb2.Append("Data:" + e.Data); using (StreamWriter sw = File.AppendText("ErrorLog.txt")) { sw.Write(sb2.ToString()); sw.Close(); }
Of course you can expand this to catch different exceptions.
You could also write to the Event Log, but unless you area system admin or have access to event logs you are SOL..
http://support.microsoft.com/kb/307024
Friday, May 03, 2013
What does Dim stand for and what is the history --- Thank you Stack Trace
Dim originally (in BASIC) stood for Dimension, as it was used to define the dimensions of an array.
(The original implementation of BASIC was Dartmouth BASIC, which descended from FORTRAN, where DIMENSION is spelled out.)
Nowadays, Dim is used to define any variable, not just arrays, so its meaning is not intuitive anymore.
Friday, April 26, 2013
Kill Task in XP
taskkill /pid /F
Force to kill aspwp.exe and then delete all C:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
Then rebuild .NET solution all will look a lot clearner.
Force to kill aspwp.exe and then delete all C:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
Then rebuild .NET solution all will look a lot clearner.
When you work in distributed environment you probably use remote desktop session as you primary method of sql server machines administration. When critical windows updates are installed or when you install system or sql server service pack installation wizard promts you to restart the box in order to complete the installation. And it happens from time to time that this machine hangs on reboot process for some reason and you can no longer connect it via remote desktop. If it was you local computer you could enter into your server room and press the reset button but if it stand thousands miles away from you it becomes a real problem.How to restart or shutdown remote machine
If you can ping this machine from other computer and you have administrators rights on that machine you may use windows utility.
On a computer that has connection to the server which needs to be restarted or shutdown go to Start -> Run and type shutdown -i
This window will show up. Press Add and type either IP or DNS of remote server.
Select shutdown or restart and press OK. That 's it. For your convenience you may run from command line constanct ping (ping servername -t) when the server actually stopped to respond to pings and when it started again.
Alternatively you can go to command prompt (start -> run -> cmd) on your workstation and Type
shutdown -r -m \\x.x.x.x
Replace x.x.x.x with the IP address or computer name of the remote machine. -r option is for restart, don't use -r if want to just shut down the system.
If you can ping this machine from other computer and you have administrators rights on that machine you may use windows utility.
On a computer that has connection to the server which needs to be restarted or shutdown go to Start -> Run and type shutdown -i
This window will show up. Press Add and type either IP or DNS of remote server.
Select shutdown or restart and press OK. That 's it. For your convenience you may run from command line constanct ping (ping servername -t) when the server actually stopped to respond to pings and when it started again.
Alternatively you can go to command prompt (start -> run -> cmd) on your workstation and Type
shutdown -r -m \\x.x.x.x
Replace x.x.x.x with the IP address or computer name of the remote machine. -r option is for restart, don't use -r if want to just shut down the system.
Demystify SQL Debugging with with Visual Studio
Here is what I did to fix this issue "FINALLY"
http://www.asp.net/data-access/tutorials/debugging-stored-procedures-vb
#1 Connect using Windows Authentication as the same account on the local machine that must have sysadmin rights in the Instance of SQL Server.
#2 They use Server Explorer and connect with that same account and then once connect right click on the DB and check "Application Debuggin. I am posting this to my blog.
Great posts. By the way I feel the pain of remote individuals, my answer tell your management that if you want fast, rapid code to fork up the dough for SQL Developer Edition and do all you coding locally with a quality source control.
Robert.
http://www.asp.net/data-access/tutorials/debugging-stored-procedures-vb
#1 Connect using Windows Authentication as the same account on the local machine that must have sysadmin rights in the Instance of SQL Server.
#2 They use Server Explorer and connect with that same account and then once connect right click on the DB and check "Application Debuggin. I am posting this to my blog.
Great posts. By the way I feel the pain of remote individuals, my answer tell your management that if you want fast, rapid code to fork up the dough for SQL Developer Edition and do all you coding locally with a quality source control.
Robert.
Wednesday, April 24, 2013
Try Catch VB.NET and C#
Try + Enter blows out exception method for vb.net
Try tab tab tab C# for Exception method
Provided by Daniel Bivens
Try tab tab tab C# for Exception method
Provided by Daniel Bivens
Opacity on Images for Web Development
CSS Style --
input[type="image"].disabled { /* Required for IE 5, 6, 7 */ /* ...or something to trigger hasLayout, like zoom: 1; */ /*/width: 100%; */ /* Theoretically for IE 8 & 9 (more valid) */ /* ...but not required as filter works too */ /* should come BEFORE filter */ -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; /* This works in IE 8 & 9 too */ /* ... but also 5, 6, 7 */ filter: alpha(opacity=35); /* Older than Firefox 0.9 */ -moz-opacity:0.35; /* Safari 1.x (pre WebKit!) */ -khtml-opacity: 0.35; /* Modern! /* Firefox 0.9+, Safari 2?, Chrome any? /* Opera 9+, IE 9+ */ opacity: 0.35; cursor:default; }
function enableElement(element) { $(element).removeClass('disabled').prop('disabled', false); }
function disableElement(element) { var obj = $(element); obj.prop('disabled', true); if (obj.prop('tagName') === 'INPUT' && obj.prop('type') === 'image') { obj.addClass('disabled'); } }
Thanks Josh Horton... Web Developer GURU....
Thursday, April 11, 2013
Code Academy - Good Stuff
HTTP Status Codes
A successful request to the server results in a response, which is the message the server sends back to you, the client.
The response from the server will contain a three-digit status code. These codes can start with a 1, 2, 3, 4, or 5, and each set of codes means something different. (You can read the full list here). They work like this:
1xx: You won't see these a lot. The server is saying, "Got it! I'm working on your request."
2xx: These mean "okay!" The server sends these when it's successfully responding to your request. (Remember when you got a "200" back from Codecademy?)
3xx: These mean "I can do what you want, but I have to do something else first." You might see this if a website has changed addresses and you're using the old one; the server might have to reroute the request before it can get you the resource you asked for.
4xx: These mean you probably made a mistake. The most famous is "404," meaning "file not found": you asked for a resource or web page that doesn't exist.
5xx: These mean the server goofed up and can't successfully respond to your request.
Wednesday, April 10, 2013
Keyboard shortcuts
Instructions
- Select one word by placing your cursor at one end of the word. Hold down the "Ctrl" key and the "Shift" key. Press the right arrow key to select the word to the right, or press the left arrow key to select the word to the left.
- Select one character at a time by holding down the "Shift" key and and using either arrow key (right or left). Select an entire line of text by holding down the "Shift" key and pressing "End", if you are at the beginning of the line, or "Home" if you are at the end of the line.
- Select an entire paragraph by placing your cursor at either the beginning or the end of that paragraph. Hold down the "Shift" key and press the up arrow, if you are at the end of the paragraph, or the down arrow, if you are at the beginning. If you are in any other section of the paragraph, this shortcut will allow you to select the remainder of the paragraph from your cursor to the end or beginning.
- Select the text from wherever your cursor is placed to one screen up, or one screen down by holding down the "Shift" key and pressing the "Page Up" button (to move up) or the "Page Down" button (to move down). These buttons may say "Pg Up" and "Pg Dn" on your keyboard.
- Select all of the text in your document or on your screen by holding down the "Ctrl" key and pressing the letter "A".
Read more: How to Select Text Using Keyboard Shortcuts | eHow.com http://www.ehow.com/how_4493907_select-text-using-keyboard-shortcuts.html#ixzz2Q54uO1Dt
Wednesday, April 03, 2013
Walt's Words of Wisdom - "Entity Framework"
To know:
If you ware working with Entity Framework be sure to know the following... Thank you Sir Walt.
1. If you are developing for 4.0 ensure all your projects in your solution are set to the same Framework
2. Install by right clicking the project and Manager NuGet Packages and install Entity Framework (Yes Nuget is smart enough to put the correct version, but to verify do the following. Do this for all projects in yoru solution (It will prevent headaches later).
Look at your App.config or Web.config and look for
.NET 4.0 = EntityFramework, Version=4.4.0.0
.NET 4.5 = EntityFramework, Version=5.0.0.0
If you ware working with Entity Framework be sure to know the following... Thank you Sir Walt.
1. If you are developing for 4.0 ensure all your projects in your solution are set to the same Framework
2. Install by right clicking the project and Manager NuGet Packages and install Entity Framework (Yes Nuget is smart enough to put the correct version, but to verify do the following. Do this for all projects in yoru solution (It will prevent headaches later).
Look at your App.config or Web.config and look for
.NET 4.0 = EntityFramework, Version=4.4.0.0
.NET 4.5 = EntityFramework, Version=5.0.0.0
Tuesday, March 26, 2013
Youtube good to know yellow line
When the red line reaches the yellow line, it means you can press the play button and continue your video without any pauses for buffering.
Friday, March 22, 2013
Tuesday, March 19, 2013
Using Statement to get 1 Scalar Value back from SQL
Public Function AddProductCategory( _ ByVal newName As String, ByVal connString As String) As Integer Dim newProdID As Int32 = 0 Dim sql As String = _ "INSERT INTO Production.ProductCategory (Name) VALUES (@Name); " _ & "SELECT CAST(scope_identity() AS int);" Using conn As New SqlConnection(connString) Dim cmd As New SqlCommand(sql, conn) cmd.Parameters.Add("@Name", SqlDbType.VarChar) cmd.Parameters("@Name").Value = newName Try conn.Open() newProdID = Convert.ToInt32(cmd.ExecuteScalar()) Catch ex As Exception Console.WriteLine(ex.Message) End Try End Using Return newProdID End Function
Monday, March 18, 2013
Working with Toolbox DataSources
Current contract I am working a lot with legacy code and find myself going over a pattern to ensure the additions I add remain in-line with the legacy code. Note the entire application is going to be re-written in about six months, so in order to save type by re-factoring I am simply following existing patterns.
Here is the key.
If a developer uses a Object or SQL Datasource you need to follow form the following:
1. ASP.NET (aka .aspx page control)
2. Next to the SQL or Object Data Source ensure the call to the SQL or OBJECT includes the data you need for step 1.
3. If you are performing OBJECT you need to expect the OBJECT that is being called to ensure the SQL or StoreProc is included for the data you need.
4. If SQL you need to ensure inline SQL is in place (Prevent Cross Site Scripting)
5. Then ensure the return to the control on the .aspx page.
6. Ensure all parameters in the INSERT, UPDATE, etc. Match the Controls #Bind("Naming_Structure") and to the object to the db, to keep things simple.
Follow the code from input to output....
Here is the key.
If a developer uses a Object or SQL Datasource you need to follow form the following:
1. ASP.NET (aka .aspx page control)
2. Next to the SQL or Object Data Source ensure the call to the SQL or OBJECT includes the data you need for step 1.
3. If you are performing OBJECT you need to expect the OBJECT that is being called to ensure the SQL or StoreProc is included for the data you need.
4. If SQL you need to ensure inline SQL is in place (Prevent Cross Site Scripting)
5. Then ensure the return to the control on the .aspx page.
6. Ensure all parameters in the INSERT, UPDATE, etc. Match the Controls #Bind("Naming_Structure") and to the object to the db, to keep things simple.
Follow the code from input to output....
Friday, March 15, 2013
SQLDataSource or ObjectDataSource
My experience with the DataSource Toolbox items (I try to stay away from them), but as a developer you always have to maintain another developer's code. Be sure to name your parameters and pass the same exact number of parameters to the calling INSERT, UPDATE, SELECT methods, it will save time and headaches.
You will have issues... More to come.
You will have issues... More to come.
Wednesday, March 13, 2013
SQL Server sp_who2 how to order
--sp_who2
DROP TABLE #sp_who2
CREATE TABLE #sp_who2
(SPID INT,
Status VARCHAR(1000) NULL,
Login SYSNAME NULL,
HostName SYSNAME NULL,
BlkBy SYSNAME NULL,
DBName SYSNAME NULL,
Command VARCHAR(1000) NULL,
CPUTime INT NULL,
DiskIO INT NULL,
LastBatch VARCHAR(1000) NULL,
ProgramName VARCHAR(1000) NULL,
SPID2 INT,
REQUESTID INT)
GO
INSERT INTO #sp_who2
EXEC sp_who2
SELECT * FROM #sp_who2 ORDER BY DiskIO DESC
ADO.NET Get Data to populate DataTable
#Region "Select Concern Status Values"
Public Function SelectProvConcernStatus() As DataTable
Dim dt As New DataTable
Try
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("conn_string").ConnectionString)
conn.Open()
Using cmd As New SqlCommand("SELECT concern_status_id, concern_status FROM tbl_provider_concern_status", conn)
cmd.CommandType = CommandType.Text
Dim sda As SqlDataAdapter = New SqlDataAdapter(cmd)
sda.Fill(dt)
End Using
End Using
Return dt
Catch ex As Exception
Throw
End Try
End Function
#End Region
Tuesday, March 12, 2013
T-SQL Library - Check if Column Exists Alter Table
Composing T-SQL to run over and over to check into source control for column change....
IF NOT EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'tbl_Provider_Concerns'
AND COLUMN_NAME = 'concern_status_id')
BEGIN
ALTER TABLE tbl_Provider_Concerns
ADD concern_status_id INT
END
ALTER TABLE tbl_Provider_Concerns
ADD CONSTRAINT FK_Status
FOREIGN KEY(concern_status_id)
REFERENCES tbl_Provider_Concern_Status(concern_status_id)
Friday, March 08, 2013
TFS 2010 Build Automation - Issue with Solution with external project in another Source Control Folder
Backgroud on TFS Structure:
>***** Top level project (***** for security purpose)
--- Development
---XX
---XXirect* (This is what I am attempting to build, more details below)
--- QA
--- Root
Actual solution through Solution Explorer
XXirect-2.5.6.sln (Includes the following projects)
--XXirect (In the XXirect Folder)
--XX_CommonMethods (In the XX Folder aka referenced project)
Under the build definition if have the following:
Status
|
Source Control Folder
|
Build Agent Folder
|
Active
|
$/*****/Development/XX/XX_CommonMethods
|
$(SourceDir)\XX\XX_CommonMethods
|
Active
|
$/*****/Development/XXirect
|
$(SourceDir)
|
When I build I get the following error:
$/*****/Development/XXirect/XXirect-2.5.6.sln - 1 error(s), 103 warning(s), View Log File
C:\Builds\4\*****\XX_DEV - Draft\Sources\XXirect-2.5.6.sln.metaproj: The project file "C:\Builds\4\*****\XX_DEV - Draft\Sources\..\XX\XX_CommonMethods\XX_CommonMethods.csproj" was not found.
I have another build that I copied this template for that works fine. It actual builds to the build server (both containing the controller (m) and agent (007). Actually those are their names, just thought it was great how you explained that in the training.
The build actually builds then copies _Published folder to another server, which works fine. Again the issue I believe lies in the Mapping…
Any help would be great.
FIX
FIX
Try the following
Status
|
Source Control Folder
|
Build Agent Folder
|
Active
|
$/*****/Development/XX/XX_CommonMethods
|
$(SourceDir)\XX\XX_CommonMethods
|
Active
|
$/*****/Development/XXirect
|
$(SourceDir)\XXirect
|
Ahmed is an independent consultant in Ottawa, Canada specialized in .NET, Biztalk, WCF, WPF, TFS and other Microsoft technologies.
Blog: http://lajak.wordpress.com
Twitter: ahmedalasaad
Ahmed Al-Asaad - 5 STARS... You are the man. You suggested fixed the issue. Thank you so much.
I am writing the following for the MSDN community to help them as well.
Yesterday, I tried building individual projects instead of the .sln
In the Build Definition the two sections that are critical to this.
Workspace
tatus
|
Source Control Folder
|
Build Agent Folder
|
Active
|
$/*****/Development/XX/XX_CommonMethods
|
$(SourceDir)\XX\XX_CommonMethods
|
Active
|
$/*****/Development/XXirect/XXirect
(Had added to go directly after the .proj file instead of the .SLN
|
$(SourceDir) (NOTE THE XXIRECT WAS NOT ADDED)
|
Process
- Items to Build
- Here I switched to point directly to the XXirect *.*proj (Note - this was the attempt to fix it do not follow this)
- Also another gotcha is Configurations to Build -AnyCPU|Dev (Note the AnyCPU sometimes has a spaceAny CPU, note the space) which can causes an issue. GOTCHA look out for that.
Thankfully, I checked my email and Ahmed posted on MSDN the following change to the Workspace, which fixed the entire problem.
Status
|
Source Control Folder
|
Build Agent Folder
|
Active
|
$/*****/Development/XX/XX_CommonMethods
|
$(SourceDir)\XX\XX_CommonMethods
|
Active
|
$/*****/Development/XXirect
|
$(SourceDir)\XXirect
|
This also required swtiching the XXIRECT in the Source Control Folder to point to the *.sln and not the *.*proj file as well as switching back the Process to point to the *.sln successfully ran the build.
KUDOS KUDOS to Ahmed.
I searched all overt the Web for 8 hours looking and working on this yesterday. Ahmed and MSDN you really came through. Thanks also for David Star on Plural Sight for an awesome tutorial.
Tuesday, March 05, 2013
Programming as a career
Quoting my old mentor... You must be able to learn, unlearn and relearn to survive in the World of Software Development (Web Development) ever changing. Thank you Doug Cain.
Friday, March 01, 2013
Friday, February 22, 2013
Thoughts from Josh
NVARCHAR - to be used because if 100 characters are set aka NVARCHAR(100), but only 10 characters are used the amount of space used is 10.
WHERE if NCHAR 100 Characters aka NCHAR(100) , but only 10 characters are used the amount of space used is 100...
Very wasteful on data storage. "KNOW YOU YOUR DATA", as Larry Leonard would say.
WHERE if NCHAR 100 Characters aka NCHAR(100) , but only 10 characters are used the amount of space used is 100...
Very wasteful on data storage. "KNOW YOU YOUR DATA", as Larry Leonard would say.
Visual Studio Build Feature
GREAT POST --- http://geeks-squad.blogspot.com/2008/07/what-does-clean-solution-under-build.html
What does "Clean Solution" under Build Menu in Visual Studio do ?
I have been using the Visual Studio 2003 and 2008 IDE everyday at work for 9 hours for almost 7 months now and still keep running into these little stuff in the IDE that either I never thought existed or seen or even if I have seen never bothered to explore further.
So, today morning, while building my project, (I usually use Ctrl+Shift+B (Build All) rather than go to the Build Menu and use the Build Solution there) from the Build Menu, I saw the Clean Solution menu that I always knew existed but never bothered to find out what for.
So, I decided to look it up on MSDN and this is what I found.
So, today morning, while building my project, (I usually use Ctrl+Shift+B (Build All) rather than go to the Build Menu and use the Build Solution there) from the Build Menu, I saw the Clean Solution menu that I always knew existed but never bothered to find out what for.
So, I decided to look it up on MSDN and this is what I found.
To build, rebuild, or clean an entire solution
In Solution Explorer, select or open the desired solution. On the Build menu, choose Build Solution, Rebuild Solution, or Clean Solution.
Choose Build or Build Solution to compile only those project files and components that have changed since the last build.
Note:
The Build command becomes Build Solution when a solution includes more than one project. Choose Rebuild Solution to "clean" the solution first, and then build all project files and components. Choose Clean Solution to delete any intermediate and output files, leaving only the project and component files, from which new instances of the intermediate and output files can then be built.
So, Clean Solution apparently cleans up ur .pdb files from the solution directory and adds them back again when you build the solution again with the new component files and the output generated by them.
Another article that explain "Clean Solution" can be found here.
But then again, my curiosity did not die there, so I continued on trying to find what exactly goes on in a "pdb" file and found some really good articles.
MSDN says
"A program database (PDB) file holds debugging and project state information that allows incremental linking of a debug configuration of your program. A PDB file is created when you build with /debug (Visual Basic/C#). You can build Visual Basic and Visual C# applications with/debug:full or /debug:pdbonly. Building with /debug:full generates debuggable code. Building with /debug:pdbonly generates PDBs but does not generate the DebuggableAttribute that tells the JIT compiler that debug information is available. Use /debug:pdbonly if you want to generate PDBs for a release build that you do not want to be debuggable.
The Visual Studio debugger uses the path to the PDB in the EXE or DLL file to find the project.pdb file. If the debugger cannot find the PDB file at that location, or if the path is invalid, for example, if the project was moved to another computer, the debugger searches the path containing the EXE followed by the symbol paths specified in the Options dialog box. This path is generally the Debugging folder in the Symbols node. The debugger will not load a PDB that does not match the binary being debugged."
Edition
|
Visual
Basic
|
C#
|
C++
|
Web Developer
|
---|---|---|---|---|
Express
| ||||
Standard
| ||||
Pro and Team
|
Table legend:
Applies
| |
Does not apply
| |
Command or commands hidden by default.
|
Other findings :
"The dll is the actual binary that executes. The PDB is the symbols that map memory locations in the binary to symbolic names for the debugger."
Anyways, that's it from me as far as pdb and "Clean Solution" is concerned. Next time will talk about Generics (one of my favorite features in C#).
Until next time,
Happy Debugging !!!
Thursday, February 21, 2013
New Job Title
Trained chimp behind the key board LOL... I heard that from a co-worker today and thought that was funny.
T-SQL Cursor example
--------------------------CURSOR CODE BEGIN------------------------------
DECLARE @id INT
DECLARE @doc_id INT
DECLARE @review_count INT
DECLARE MyCursor CURSOR FAST_FORWARD FOR
SELECT
doc_id,
SUBSTRING(short_desc, 6, 6) AS id
FROM tbl_client_doc cd
WHERE
cd.doc_type_id = 18
AND
cd.short_desc LIKE "XYZ: %'
AND
cd.note_desc = ''
ORDER BY
cd.doc_type_id DESC
OPEN TarCursor
FETCH NEXT FROM MyCursor INTO @doc_id, @id
WHILE @@FETCH_STATUS = 0
BEGIN
SET @review_count = (SELECT COUNT(answer_id) FROM tbl_review_gen WHERE id = @id)
IF @review_count > 0
BEGIN
PRINT 'DELETE FROM tbl_client_doc WHERE doc_id = ' + CONVERT(varchar(10), @doc_id)
END
FETCH NEXT FROM MyCursor INTO @doc_id, @id ---- Have to move to the next row
END
--CLOSE MyCusor
DEALLOCATE MyCursor
GO
--------------------------CURSOR CODE END-------------------------------
Tuesday, February 19, 2013
DropDownList set dl.SelectedValue
Private Sub dg_srvc_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg_srvc.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim dl_span As DropDownList
Dim t As Label
dl_span = CType(e.Item.FindControl("dl_span"), DropDownList)
dl_span.SelectedValue = dl_span.Items.IndexOf(dl_span.Items.FindByText(s_span.Trim.ToLower))
t = CType(e.Item.FindControl("temp"), Label)
t.Text = s_span.Trim
End If
WARNING: ENSURE your values if hard coded match the value from the DB...
Visual Studio Windows opening in different Window Panes?
If your Visual Studio 2012 or any other version is opening Windows in different panes try the following:
File Menu
--- Window
---- Reset Window Layout
Pretty good stuff --- Also found "Auto Hide All" good shortcut to get the full screen to code with.
Friday, February 15, 2013
Databinding
MSDN - Data-binding expressions are contained within <%# and %> delimiters and use the Eval and Bind functions. The Eval function is used to define one-way (read-only) binding. The Bind function is used for two-way (updatable) binding. In addition to calling Eval and Bind methods to perform data binding in a data-binding expression, you can call any publicly scoped code within the <%# and %> delimiters to execute that code and return a value during page processing.
Search for Text in SQL Server DB
use DB_NAME
SELECT DISTINCT
DB_NAME() AS DatabaseName,
OBJECT_SCHEMA_NAME(id) AS SchemaName,
OBJECT_NAME(id) AS ObjectName,
SUBSTRING(text, PATINDEX('%YOUR_SEARCH_TEXT%',text) - 10, 100) AS TextLocation
FROM sys.syscomments
WHERE text LIKE '%YOUR_SEARCH_TEXT%'
ORDER BY 1, 2, 3
Tuesday, February 12, 2013
SQL Server Check --- IF Exists
IF EXISTS(SELECT * FROM tempdb.dbo.sysobjects WHERE ID = OBJECT_ID(N'tempdb..#temp_det_for_mst'))
BEGIN
DROP TABLE #temp_det_for_mst
END
Tuesday, February 05, 2013
Entity Framework (Credit Walt Daniels)
Wiring up Entity Framework to DropDownList ASP.NET.
Prereq --- Setup Entity Framework.
Private Sub FillSource()
ctx = New Context()
Dim qry = From p In ctx.tbl_names
Where p.ACTIVE = True
Order By p.name
Select p.id, p.name
ddlFundSource.DataSource = qry.ToList()
ddlFundSource.DataValueField = id"
ddlFundSource.DataTextField = "name"
ddlFundSource.DataBind()
ddlFundSource.Items.Insert(0, New ListItem("[Any Fund]", "0")) ' Tip if you want to add a default value.
End Sub
Prereq --- Setup Entity Framework.
Private Sub FillSource()
ctx = New Context()
Dim qry = From p In ctx.tbl_names
Where p.ACTIVE = True
Order By p.name
Select p.id, p.name
ddlFundSource.DataSource = qry.ToList()
ddlFundSource.DataValueField = id"
ddlFundSource.DataTextField = "name"
ddlFundSource.DataBind()
ddlFundSource.Items.Insert(0, New ListItem("[Any Fund]", "0")) ' Tip if you want to add a default value.
End Sub
Wednesday, January 30, 2013
Looping with ADO.NET on DataTable filled from SQL
Private Sub IsAgencyFormCompleted()
Dim application_id As Int32
Dim sqlString As String
Dim dtl_id As String = String.Empty
Dim dt As New DataTable()
Dim MyCtrl As ctrl_db_commands
If Not Session("application_id") Is Nothing Then
Try
application_id = Int32.Parse(Session("application_id"))
'SQL to check to see if the Agency Form is completed
sqlString = "SELECT agcy_xxx_number, agcy_npx_number, agcy_number, agcy_primary_contact_title, agcy_executive_director, agcy_medical_director, agcy_entity_type_id, agcy_tax_status FROM [dbo].[TBL_101_APPLICATION] WHERE application_id = " & application_id
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("conn").ConnectionString)
conn.Open()
Using sda As New SqlDataAdapter(sqlString, conn)
sda.Fill(dt)
End Using
End Using
Catch ex As Exception
Throw New ArgumentException("Exception Occured Contact Cardinal Innovations Solutions Delievery")
End Try
End If
For Each dataRow As DataRow In dt.Rows
For Each dataColumn As DataColumn In dt.Columns
Dim fieldValue As String = dataRow(dataColumn).ToString()
'The AgencyForm is not completed Exit For and display message
If (fieldValue = "" Or fieldValue = "-1") Then
Me.Master.ShowSysMessage("Please complete the entire Section1-1 (Agency) before adding Facilities", "Error")
MyCtrl = DirectCast(Me.fv1.FindControl("ctrl_db_commands1"), ctrl_db_commands)
MyCtrl.Show_Add = False
MyCtrl.Show_Cancel = False
MyCtrl.Header_Text_HTML = "Please complete the entire Section1-1 (Agency) before adding Facilities"
Exit For
End If
Next
Next
End Sub
Dim application_id As Int32
Dim sqlString As String
Dim dtl_id As String = String.Empty
Dim dt As New DataTable()
Dim MyCtrl As ctrl_db_commands
If Not Session("application_id") Is Nothing Then
Try
application_id = Int32.Parse(Session("application_id"))
'SQL to check to see if the Agency Form is completed
sqlString = "SELECT agcy_xxx_number, agcy_npx_number, agcy_number, agcy_primary_contact_title, agcy_executive_director, agcy_medical_director, agcy_entity_type_id, agcy_tax_status FROM [dbo].[TBL_101_APPLICATION] WHERE application_id = " & application_id
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("conn").ConnectionString)
conn.Open()
Using sda As New SqlDataAdapter(sqlString, conn)
sda.Fill(dt)
End Using
End Using
Catch ex As Exception
Throw New ArgumentException("Exception Occured Contact Cardinal Innovations Solutions Delievery")
End Try
End If
For Each dataRow As DataRow In dt.Rows
For Each dataColumn As DataColumn In dt.Columns
Dim fieldValue As String = dataRow(dataColumn).ToString()
'The AgencyForm is not completed Exit For and display message
If (fieldValue = "" Or fieldValue = "-1") Then
Me.Master.ShowSysMessage("Please complete the entire Section1-1 (Agency) before adding Facilities", "Error")
MyCtrl = DirectCast(Me.fv1.FindControl("ctrl_db_commands1"), ctrl_db_commands)
MyCtrl.Show_Add = False
MyCtrl.Show_Cancel = False
MyCtrl.Header_Text_HTML = "Please complete the entire Section1-1 (Agency) before adding Facilities"
Exit For
End If
Next
Next
End Sub
Programmer productivity -- Dr. Dobbs
Article on ALM
products, but the first part is so true…
Worth a read
Multitasking is good
when it comes to computer programs, letting them do more with less. But when
computer programmers start multitasking, productivity flies out the door.
For one thing, when
programmers have to shift tasks, it takes "a really, really, really long
time," says Joel Spolsky, host of the Joel On Software Web site and
co-founder of Fog Creek Software. Programmers have to keep a lot of things in
their heads at once, Spolsky says, and the more they remember, the more
productive they are. "A programmer coding at full throttle is keeping
zillions of things in their head at once," he says, "everything from
names of variables, data structures, important APIs, the names of utility
functions that they call a lot, even the name of the subdirectory where they
store their source code."
On top of that, as
applications have become more collaborative, complex, modular, and distributed,
developers are having to track an increasing number of tasks and deal with more
interruptions from the people with whom they're collaborating. As a result,
they're multitasking more frequently and becoming less productive.
How bad is the
problem? Developers spend an average of 11 minutes on one task before being
interrupted to deal with another, according to Gloria Mark of the University of
California at Irvine's Department of Informatics, who has spent years examining
developers' work environments. It then takes them 25 minutes to return to the
original task.
Keeping programmers
productive in these fragmented work environments is a challenge for large
software developers as well as for IT shops developing for end users. In both
cases, application life-cycle management tools and processes can help. They
automate steps -- such as change management, build processes, and testing -- in
the development process, off-loading work from developers and cutting back on
the number of interruptions they face.
Rest
of Article --- http://www.drdobbs.com/tools/programmer-productivity/220100341
Tuesday, January 29, 2013
ASP.NET Coding Thoughts
Sometimes you just
have to bang your head until you get it.
I worked till 9:00 PM EST yesterday to figure out the Network App App.
It was very
challenging and frustrating, but I did learn quite a few things.
Using TryCast() or
DirectCast() methods don't work well if
you are not in the correct container that you are trying to cast, aka
our famous formview container.
Hint Hint… the most
of the user controls are all in the formview --- That got me.
I keep saying to
myself, why the hell are you not picking up the usercontrol (Then it clicked)
The past programmer did a great deed by hard
coding values on properties when you pass the value to the properties… No problem that was fixed for the Show_Add() Property.
Finally the call of
the user control was overwriting the properties that I set because of the
ASP.NET Page Load Cycle. As a result the
user control properties value sets are set in the Me.PreRenderComplete Event
(GOTCHA)
So in all lessons
learned.
My takeaways.
- Use DirectCast when you know the value type and in this scenario were casting the user control with ID = ctrl_db_commands1
- Find the control in the correct container, never trust old applications and always research where these controls exist
- If your properties are not changing you better debug and find out why in this case the values where hard coded in the properties, which was updated to work correctly.
Wow, what a
challenge, what next does work have for me, from this point forward I will not
take any of this code for granted.
Friday, January 18, 2013
Clustered and Non-Clustered Indexes by Vijay Modi
What is cluster and Non-Cluster index and why we need it? Do you know? Just read this article and you will know all about it.
Most database administrators are familiar with the potential performance benefits they can gain through the judicious use of indexes on database tables. Indexes allow you to speed query performance on commonly used columns and improve the overall processing speed of your database.
Microsoft SQL Server supports two types of indexes:
-> Clustered indexes define the physical sorting of a database table’s rows in the storage media. For this reason, each database table may have only one clustered index. If a PRIMARY KEY constraint is created for a database table and no clustered index currently exists for that table, SQL Server automatically creates a clustered index on the primary key.
-> Non-clustered indexes are created outside of the database table and contain a sorted list of references to the table itself.
SQL Server 2000 supports a maximum of 249 non-clustered indexes per table. However, it’s important to keep in mind that non-clustered indexes slow down the data modification and insertion process, so indexes should be kept to a minimum
One of the hardest tasks facing database administrators is the selection of appropriate columns for non-clustered indexes. You should consider creating non-clustered indexes on any columns that are frequently referenced in the WHERE clauses of SQL statements. Other good candidates are columns referenced by JOIN and GROUP BY operations.
You may wish to also consider creating non-clustered indexes that cover all of the columns used by certain frequently issued queries. These queries are referred to as “covered queries” and experience excellent performance gains.
SQL Server provides a wonderful facility known as the Index Tuning Wizard which greatly enhances the index selection process. To use this tool, first use SQL Profiler to capture a trace of the activity for which you wish to optimize performance. You may wish to run the trace for an extended period of time to capture a wide range of activity. Then, using Enterprise Manager, start the Index Tuning Wizard and instruct it to recommend indexes based upon the captured trace. It will not only suggest appropriate columns for queries but also provide you with an estimate of the performance increase you’ll experience after making those changes!
Monday, January 14, 2013
Calendar Mask and AJAX
<asp:TextBox ID="txt_prov_srvc_from_dt" runat="server" MaxLength="10" />
<asp:ImageButton ID="ibtnServFromDtCal" AlternateText="Calendar" ImageUrl="~/images/calendar_icon_blue.gif" runat="server" CausesValidation="false" />
<ajaxtoolkit:MaskedEditExtender ID="maskExtenderServFromDtCal" TargetControlID="txt_prov_srvc_from_dt" MaskType="None" Mask="99/99/9999" ClearMaskOnLostFocus="False" runat="server" />
<ajaxtoolkit:CalendarExtender ID="maskCalExtenderServFromDtCal" TargetControlID="txt_prov_srvc_from_dt" PopupButtonID="ibtnServFromDtCal" Format="MM/dd/yyyy" runat="server" />
<asp:CompareValidator ID="ProvSrvcFromDtValidator" runat="server" ErrorMessage="CompareValidator" Type="Date" ControlToValidate="txt_prov_srvc_from_dt" Operator="DataTypeCheck" Display="Dynamic" Font-Bold="True">?</asp:CompareValidator>
<asp:TextBox ID="txt_prov_srvc_to_dt" runat="server" MaxLength="10" />
<asp:ImageButton ID="ibtnServToDtCal" AlternateText="Calendar" ImageUrl="~/images/calendar_icon_blue.gif" runat="server" CausesValidation="false" />
<ajaxtoolkit:MaskedEditExtender ID="maskExtenderServToDtCal" TargetControlID="txt_prov_srvc_to_dt" MaskType="None" Mask="99/99/9999" ClearMaskOnLostFocus="False" runat="server" />
<ajaxtoolkit:CalendarExtender ID="maskCalExtenderServToDtCal" TargetControlID="txt_prov_srvc_to_dt" PopupButtonID="ibtnServToDtCal" Format="MM/dd/yyyy" runat="server" />
<asp:CompareValidator ID="ProvSrvcToDtValidator" runat="server" ErrorMessage="CompareValidator" Type="Date" ControlToValidate="txt_prov_srvc_to_dt" Operator="DataTypeCheck" Display="Dynamic" Font-Bold="True">?</asp:CompareValidator>
Friday, January 11, 2013
ADO.NET 2012 - GET DATA from SQL with Using Statements
VB.NET
Private Function GetData() As String
Dim intDataID As Integer
Dim strFinalizedDate As String = "Not Completed"
Try
intDataID = Int32.Parse(lblDataID.Text)
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("conn_string").ConnectionString)
conn.Open()
Using cmd As New SqlCommand("SELECT update_dt FROM table WHERE data_id = " & intDataID, conn)
cmd.CommandType = CommandType.Text
Using reader As SqlDataReader = cmd.ExecuteReader()
If reader.HasRows Then
While reader.Read()
strFinalizedDate = reader("update_dt").ToString()
End While
End If
End Using
End Using
End Using
Return strFinalizedDate
Catch ex As Exception
Throw
End Try
End Function
C#
try {
intDataID = Int32.Parse(lblDataID.Text);
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings("conn_string").ConnectionString)) {
conn.Open();
using (SqlCommand cmd = new SqlCommand("SELECT update_dt FROM table WHERE data_id = " + intDataID, conn)) {
cmd.CommandType = CommandType.Text;
using (SqlDataReader reader = cmd.ExecuteReader()) {
if (reader.HasRows) {
while (reader.Read()) {
strFinalizedDate = reader("update_dt").ToString();
}
}
}
}
}
return strFinalizedDate;
} catch (Exception ex) {
throw;
}
Private Function GetData() As String
Dim intDataID As Integer
Dim strFinalizedDate As String = "Not Completed"
Try
intDataID = Int32.Parse(lblDataID.Text)
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("conn_string").ConnectionString)
conn.Open()
Using cmd As New SqlCommand("SELECT update_dt FROM table WHERE data_id = " & intDataID, conn)
cmd.CommandType = CommandType.Text
Using reader As SqlDataReader = cmd.ExecuteReader()
If reader.HasRows Then
While reader.Read()
strFinalizedDate = reader("update_dt").ToString()
End While
End If
End Using
End Using
End Using
Return strFinalizedDate
Catch ex As Exception
Throw
End Try
End Function
C#
try {
intDataID = Int32.Parse(lblDataID.Text);
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings("conn_string").ConnectionString)) {
conn.Open();
using (SqlCommand cmd = new SqlCommand("SELECT update_dt FROM table WHERE data_id = " + intDataID, conn)) {
cmd.CommandType = CommandType.Text;
using (SqlDataReader reader = cmd.ExecuteReader()) {
if (reader.HasRows) {
while (reader.Read()) {
strFinalizedDate = reader("update_dt").ToString();
}
}
}
}
}
return strFinalizedDate;
} catch (Exception ex) {
throw;
}
Thursday, January 10, 2013
To find out who is connected to database in SQL Server
There are three ways to find who is connected to a database in sqlserver.
First one:
Second One:
First one:
- Use the SQL SERVER Management Studio -- Management -- Activity Monitor
- This gives a list of users, database names, status, command, transactions, application with which they are using the database, CPU, IO and Memory usage, Login time etc.
Second One:
- Use the built in stored procedure called sp_who2
- Run the command exec sp_who2
- This gives a list of users, database names, status, command, program with which they are using the database, CPU time, Login time etc.
Tuesday, January 08, 2013
Happy New Year
Goals for New Year
- .NET Entity Framework, know backwards and forwards
- JQuery
- Keep up with SharePoint
- Most important, GET IN SHAPE
- .NET Entity Framework, know backwards and forwards
- JQuery
- Keep up with SharePoint
- Most important, GET IN SHAPE
Thursday, December 27, 2012
Importance of Audit in Windows Servers
From - http://www.techotopia.com/index.php/Auditing_Windows_Server_2008_File_and_Folder_Access
Importance of Folder and File Auditing to track changes on Windows Servers. If something gets change that your job requires you to be responsible, it is to your benefit to:
A) Lock down and password protect and minimize the password to (3) people only
B) Turn File Auditing on.
C) Ensure that the only change capability is assigned to individuals rather than a service account. If a service account is compromised you will not know be able to track the changes down.
Importance of Folder and File Auditing to track changes on Windows Servers. If something gets change that your job requires you to be responsible, it is to your benefit to:
A) Lock down and password protect and minimize the password to (3) people only
B) Turn File Auditing on.
C) Ensure that the only change capability is assigned to individuals rather than a service account. If a service account is compromised you will not know be able to track the changes down.
Subscribe to:
Posts (Atom)