Pages

Sunday, July 8, 2012

I Don't Trust Sourcegear Vault

Sorry to have to say this, but in my short time trying to use it I have had numerous issues like:
  • Don't use the latest version, use this special old release.  It's the only one that works for us (version compatibility issues).
  • You check in a project and when you check back out it's in the wrong place.
    • This makes it so when you browse your tree, all the files show as missing, which makes me panic every single time.
    • If you try to fix it incorrectly, it adds your whole project to a folder inside your project like root/myProject/myProject/...all my folders - again
  • It locks all your files when you told it not to.
  • At least once in every project, things have gotten so banjaxed that I have had to delete and re-upload the entire source set, meaning all previous revisions are lost.
Bottom line, Vault has lost my confidence. Now only on the rarest occasion, when all the pressure is completely off to get my work done, will I dare to try a check-in.  Because about 65% of the time, trying to check in my source means losing a significant part of a workday trying to sort out some stupid problem.

Incidentally, I have used Subversion many times, and NEVER had any of these problems, or really had to dig through manuals for answers.

...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Friday, July 6, 2012

MSSQL: Find the next available number in a sequence

 So I have this data table, with a non-key column, and I need to write a SQL Query to find the next unused number in the sequence that is greater than a certain starting number.

It's like this:
A long time ago, the table started somewhere around 1000.  This is not a key column, and some of the older records have been archived out of the table.  So I have a weird number that will serve as my minimum.   BUT! there are also some wacky big numbers in the system and I don't want to do a max(n)+1.

Here's a beakdown:

0-35956these numbers are there, with lots of missing numbers and gaps due to archiving.
35957-1904121900a few of these are there, I want to find the next available number in this region.
1904121901 and upI want to ignore these numbers, and not use them (until all the numbers leading up to here are filled).

My Goal here is to create a SQL Query I can run once to find the next available number (meaning the lowest number above 35957 that does not exist in the column).

Here is what worked.

select min(Item_No)+1 as NextID
from Data_Table DT
where not exists
(select 1 from Data_Table DT2 where DT2.Item_No=DT.Item_No+1)
and Item_No > 35956

...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Tuesday, May 22, 2012

Avoiding SQL Injection Attacks

Take a simple SQL Query.

Select account_number from users where username='USER' and password='PASSWORD' This might be the kind of query you'd use to see if a user entered his username and password correctly.  If you get an account_id then the user is logged in.

So, you put a couple of text boxes on a login page and try to pass the values from the text boxes to the query, like this.

string USER=tbUser.text;
string PASSWORD=tbPassword.text;
string SQL="Select account_number from users where username='" + USER + "' and password='" + PASSWORD + "'"
That way if the user types in "Bob" and "MyPassword" the query executed looks like this.

Select account_number from users where username='Bob' and password='MyPassword'  Perfect.  This works great, and was a pretty standard way of doing this kind of query for a very long time, dating back to before the world wide web.  But what if a SQL-savvy hacker wants to see what kind of mischief he can cause, and tries playing with your SQL's head.  What if he entered something like this...

Username: ' or ''='
Password: ' or ''='

What does that do to our query?

Select account_number from users where username='' or ''='' and password='' or ''='' There is a really good chance that this query will bring back all the records in your database, and then think that this user is correctly logged into the very first one.  Note that login queries are not the only kind that can be hacked this way, but they are the easiest targets.  It could just as easily be your help ticket system, or anything else exposed to the web.

This is called a SQL injection attack. It's very common, but luckily it's very easy to thwart.  But there are some programmers who go about it the wrong way.

How not to protect yourself.
  1. Don't think your site is too small to get noticed and attacked.
  2. Don't  rely on Javascript, as it is easily disabled.
  3. Don't rely on Flash, as there are still people who hate it and will not load it on their browsers.
  4. Don't rely on HTML settings like maximum character lengths. They can be dispatched.
How to protect yourself.
An easy way to render SQL Injection attacks ineffective is to use sql parameters.  The not so easy part of that - if you have a massive web site - is that you have to edit ALL of your SQL that is exposed to the web.  in SQL Server, you do that like this:
string SQL="Select account_number from users where username=@USER and password=@PASSWORD"; Then, in your query you use parameters to fill in the values, like this:
myCommand.Parameters.AddWithValue("@USER", username.text);
myCommand.Parameters.AddWithValue("@PASSWORD", password.text);
Now (at least in SQL Server), no matter what they enter, it will be treated as query values.  if there is no user who's name and password are ' or ''=', then they will not be logged in.  I know it's a hassle to recode all your website queries.  But nowhere near as big a hassle as having a massive data breach to deal with.


...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Thursday, March 22, 2012

Sorting a non-SQL Dataset

So I have an ASP.NET web site and the data is coming not from a SQL Server database, but from a web service.  I have executed the Web call and gathered the data into a dataset, and I wish to sort the data inversely by job order number, floating the newest job orders to the top.

As it turns out, there is no Dataset.Sort command, but there is this.

DataRow[] SortedRows = JobsDataTable.Select("isOpen = 1", "jobOrderID desc");

This gives back a sorted (and also filtered) array of DataRows based on the criteria you use. 

Now, you can't databind to a DataRow array, but if you are using databinding, the DataGrid or DataGridView can filter and sort for you, so you wouldn't need to use this technique.



Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Saturday, March 17, 2012

Making an Image into a Usable Web Background.

 Ok, you have this great image and you want to make it the backdrop for your company web page.  Let's pick this one.
Photo of a building.
Beautiful.  But look what happens when you use it as a web backdrop.

OMG you can't read a thing!  So let's try playing with the contrast...

brightness+contrast
 Not this!  It's washed out all the details!  Maybe the levels...
 Closer, but there must be a better way.  And there is!  The problem is that we're thinking like engineers and not artists.  Try this.

Add a layer of White over the top of the image.  Then set the transparency of that layer to about 85%  This trick also works for dark backgrounds, just fill the new layer with black.



...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Friday, March 16, 2012

C#.NET Finding the First Day of the Week in One Line of Code

while (myDate.DayOfWeek != DayOfWeek.Sunday) { myDate = myDate.AddDays(-1); }


Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Thursday, March 15, 2012

So, I deleted and recreated a dataset in my Visual Studio Project.

Now, the IDE is all banjaxed, and confused.

Note:

My Solution Explorer
 Here is the shiny new dataset in the Solution Explorer.  Now look in my Data Sources pane.
My Data Sources Pane
...and no amount of refreshing, reloading, or rebooting fixes it.

The Solution
This was an odd one to be sure.  but looking at the properties window in the LotTravellerDataset1.xsd, the name property was set to "Dataset1".  Changing this property fixed the issue.


Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Using a Stored Procedure that Returns Multiple Results

Microsoft did a brilliant thing in SQL Server.  I applaud them for this.  You can actually pack more than one SQL Query into a stored procedure and have a single procedure return multiple result sets in one pass.  So I used this feature to write a stored procedure that gathers all the data I need for a certain .rdlc report in my app.  Now I can use this one stored procedure to gather all the data in one fell swoop.

I have done this kind of multiple result set stored procedures in the past and it's a simple matter in code to sort out the data tables, as they are returned in order. Here is some sample code for another instance of this method.

/// <summary>
/// gets the dataset from the database.
/// </summary>
public void Load_Data()
{
    SqlCommand myCommand = new SqlCommand("[dbo].[ExtractWebData]", myConnection);
    myCommand.CommandType = CommandType.StoredProcedure;

    System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(myCommand);
    ds = new DataSet();
    adapter.Fill(ds);
    ds.Tables[0].TableName = "Customers";
    ds.Tables[1].TableName = "Purchase_Orders";
    ds.Tables[2].TableName = "Purchase_Order_Details";
    ds.Tables[3].TableName = "Inventory";           
}

Now if there was just some way to use that in a report.  It would be great to use a stored procedure to twist all the data into shape before handing it off to a reporting tool!  So you create an xsd. You add a table adapter.
You tell it to use your existing stored procedure.

 You select your stored procedure, and there's the first dataset... But wait.  How do you tell it where the other result sets are?  I want to use all 3 datasets! 



Except that you can't do that.  You see, the .rdlc report requires that you have the data available at design time in order to design the report.  And there is no way to import multiple datasets at once into the .xsd at design time.

From this document: http://msdn.microsoft.com/en-us/library/dd239331.aspx

If multiple result sets are retrieved through a single query, only the first result set is processed, and all other result sets are ignored. For example, when you run the following query in the text-based query designer, only the result set for Production.Product appears in the result pane:
SELECT ProductID FROM Production.Product
GO
SELECT ContactID FROM Person.Contact
I have no idea what the text-based query designer is, but as we saw in SQL Server Management Studio...



In my opinion, this is an EPIC DESIGN FAIL on the part of Microsoft.

We know from the earlier code snippet that Visual Studio can access the data, it just - for some stupid reason - is designed in such a way as to disable this feature in certain cases.  This is completely unacceptable.  But until Microsoft fixes this glaring, stupid, boneheaded omission, we're stuck with it.

Now, I know this blog has no regular readers.  You didn't find this page because you're a fan of Visual Studio Journey.  You found it because you were googling for this problem, and there were no answers anywhere else.  I wish I had better news, but I don't.

Here is the only way I know to work around this issue.  Unravel your stored procedure and execute the whole thing in your client.  Convert each piece into individual queries, and add those to your .xsd.

Alternately, you could split your stored procedure into multiple pieces, like Proc1, Proc2, Proc3... but then you've kind of lost the convenience of the one-stop shopping the stored procedure offers.

Just to be clear: I think that the ability to return multiple result sets from a stored procedure is awesome!  Kudos to the SQL Server development team.  If only the Visual Studio guys would catch some of that brilliance, things would be great.

Addendum:
Just to make myself clear, I think that this feature has awesome potential and multi-table stored procedures are still incredibly useful in Visual Studio.  They just are not usable for rdlc reports (the one thing they would be most ideally suited for in an ideal world).

...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Tuesday, March 6, 2012

How to easily compare 2 SQL Server Databases.

NOTE: this is for SQL SERVER databases only.  It will not sync Oracle to Interbase or MySql to Sybase.  However, application of this technique may apply to any two databases of the same type. (i.e. oracle to oracle)

I had lost access to the  production database for a time, and wanted to ensure that I had propagated all my recent changes from Development to production - without spending $895 for a SQL management and database analysis system.

So here's how I proceeded to sync my tables from one database to the other.

Open the Production database (or a current backup of it) in SQL Server Management studio.
use this query:
SELECT
    TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT, IS_NULLABLE, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_PRECISION_RADIX, NUMERIC_SCALE, DATETIME_PRECISION
FROM INFORMATION_SCHEMA.COLUMNS
where TABLE_SCHEMA='dbo'
order by 1,2,4
Note: these columns were important to me, feel free to modify the columns as you see fit.  Also I only cared about the 'dbo' schema, so I filtered for that.  Your needs may vary.

This will give you the column info for all tables in the 'dbo' schema.

Now, save the data by right clicking the grid and selecting Save Results As.
Give it a name like Production_Schema and save as .txt.

Note: csv works too, but I find txt easier to compare.

Next do the same with the development database, naming it something like Development_Schema.txt.

Now you need a diff tool like WinMerge.  Compare these 2 files to see where they differ.  The text files cover all columns in all datatables and views in the schema.

Now go through the differences and see what changes have to be made in production so your software doesn't crash.  When I did this, I noted that there were some changes that were not ready for prime-time yet, so I left them unfixed in production.

The only thing left to compare once this is complete are the stored procedures and functions.  I just made a fresh, empty query and did a Script Stored Procedure As > Drop and Create to > Clipboard and pasted every one of them into the query. I saved it as AllFunctions.SQL and ran it in production to sync the functions.


 I hope this helps!

Comments are welcome!
...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Wednesday, February 29, 2012

Using Page Properties in ASP.net

 This tutorial will show you how to create and use a page property in ASP.NET.  In this example, the requirement is to randomly select a flash video and embed it into a web page.

First, we create a page property in the code-behind page (C# file).


public partial class _Default : System.Web.UI.Page
{
    //name of the video we're showing.
    string thisvideo = "";

    //this is the read-only property. In the page it'll be seen as <%=VideoUrl %>
    public string VideoUrl
    {
    //it only has a 'get' no set.
        get
        {
            return "SomeString";
        }
    }

Now we embed the property in the HTML like this...


            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="400" height="300"
                id="FLVPlayer">
                <param name="movie" value="flv/FLVPlayer_Progressive.swf" />
                <param name="quality" value="high" />
                <param name="wmode" value="opaque" />
                <param name="scale" value="noscale" />
                <param name="salign" value="lt" />
                <param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=flv/Clear_Skin_1&amp;streamName=<%=VideoUrl %>&amp;autoPlay=true&amp;autoRewind=true" />
                <param name="swfversion" value="8,0,0,0" />
                <!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
                <param name="expressinstall" value="js/expressInstall.swf" />
                <!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="flv/FLVPlayer_Progressive.swf"
                    width="400" height="300">
                    <!--<![endif]-->
                    <param name="quality" value="high" />
                    <param name="wmode" value="opaque" />
                    <param name="scale" value="noscale" />
                    <param name="salign" value="lt" />
                    <param name="FlashVars" value="&amp;MM_ComponentVersion=1&amp;skinName=flv/Clear_Skin_1&amp;streamName=<%=VideoUrl %>&amp;autoPlay=true&amp;autoRewind=true" />
                    <param name="swfversion" value="8,0,0,0" />
                    <param name="expressinstall" value="js/expressInstall.swf" />
                    <!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
                    <div>
                        <h4>
                            Content on this page requires a newer version of Adobe Flash Player.</h4>
                        <p>
                            <a href="http://www.adobe.com/go/getflashplayer">
                                <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif"
                                    alt="Get Adobe Flash player" /></a></p>
                    </div>
                    <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
Ok, this seems needlessly complicated, but note the green text.  This is the page property we created in the code behind page...



Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Thursday, February 16, 2012

Open a Web Page from C#.NET

How to easily open a web page from your C# App.

System.Diagnostics.Process.Start("http://209software.com/");



Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Tuesday, February 14, 2012

Easy Javascript Magnifying Glass

I had to do a report listing emails sent from my system... the report was going to be huge with all the text from the emails included, so I wrote a quick mouseover magnifier that bumped up the size of the text.

Behold.
<div onmouseover="this.style.fontSize='1em'" onmouseout="this.style.fontSize='.5em'">


The fun parts of this that matter are...
onmouseover="this.style.fontSize='1em'" 
and 
onmouseout="this.style.fontSize='.5em'"

These, when applied to the div, will cause the text in the grid to change size accordingly.

Sample - mouse over this to expand:
I had to do a report listing emails sent from my system... the report was going to be huge with all the text from the emails included, so I wrote a quick mouseover magnifier that bumped up the size of the text.

Behold.
<div onmouseover="this.style.fontSize='1em'" onmouseout="this.style.fontSize='.5em'">


The fun parts of this that matter are...
onmouseover="this.style.fontSize='1em'" 
and 
onmouseout="this.style.fontSize='.5em'"

These, when applied to the div, will cause the text in the grid to change size accordingly.


Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Monday, January 16, 2012

[INTERSOLV][ODBC Paradox driver][Paradox]Network initialization failed.

If you're seeing a...

[INTERSOLV][ODBC Paradox driver][Paradox]Network initialization failed.

... or a ...

[INTERSOLV][ODBC Paradox driver][Paradox]Directory is controlled by other .NET file.

... message, you're probably  trying to connect an ASP.NET or VS.NET Program to a Paradox database.

You've been all over the internet and there is some stuff about not being able to work on a SUBST path, but nothing you try works.  If you use the SUBST path you get Network initialization failed, while using the real path gives Directory is controlled by other .NET file.


...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Wednesday, December 21, 2011

Just a Little Question

Does Microsoft purposely update their sunsetting OS's (like WinXP) with patches that will make them bog down and frustrate people - hoping that they will get so angry that they will run out and buy a new machine?  

From what I can see, they certainly do!


Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Tuesday, December 20, 2011

Incrementing a Non Numeric Index in SQL Server

So I have this client, and all his sales invoices in the old system are either numeric, or they are numeric (1000) with a single character prefix (C1000).   We want to auto increment the index automatically, but the autoincrement stuff is not going to work here.

So I wrote a function based on this SQL.

select 'C' + isnull(cast(1+max( cast(SUBSTRING(Invoice_no,2,99) as int)) as varchar),'1000')
from Sales where Invoice_No like 'C%'
Let's work from the inside out.
  1. Invoice_no is the column to increment.  ('C1234')
  2. first we substring the first character off with SUBSTRING(Invoice_no,2,99) ('1234')
  3. we use cast to find the integer of it (1234)
  4. we use 1+max to aggregate (find the max value of this integer) and add one. (1235)
  5. we cast the result back to a varchar ('1235')
  6. then - if isnull gives us a nulll, we use the hard-coded value of '1000'
  7. we prepend the 'C' back on  ('C1235')

Now we make this into a function so we can use it like "GetDate()" in the default value of the column.

ALTER FUNCTION [dbo].[NextSalesID] ()

RETURNS varchar(10)
AS
BEGIN
    DECLARE @Answer varchar(10)   
    select @Answer= 'C' + isnull(cast(1+max( cast(SUBSTRING(Invoice_no,2,99) as int)) as varchar),'1000')
    from Sales where Invoice_No like 'C%'
    RETURN @Answer
END
 Now we have to add it as the default value for our column.  This is accomplished by editing the table in SQL Server Management Studio, selecting the column, and...
Binding a scalar Function to a Column Default
MAKE SURE that management studio doesn't add quotes '' around your function name.





Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Tuesday, December 6, 2011

A Generic Error Logging Object

 There are certain tasks that you find yourself doing over and over in multiple projects - and at some point it makes sense to just create a gizmo and re-use it.  Here is my logging object that can log messages (errors or just messages) to files and to a database.
Enjoy.

 If you want to log to a database, you must create the data table.



Next, add this object to your project (Project-Add New Item-C# Class)
Name the new object "log.cs"


Now, all you need to do to from your app is add a call to log. ...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Sunday, November 27, 2011

Insecure Security

Your password must be at least 12 characters, and include capital and lowercase, numbers, and punctuation marks.  It cannot be any of your last 10 passwords.  Also, you must change it every 10 days.
And, since we all have online accounts at 25 or more websites, all with different password strength requirements, that means that most of us either...
  • program our browsers to remember our passwords
  • create a text document to keep all our passwords
  • or, write them on a sticky note and paste them all over our desk.
Now, many sites are actively seeking to defeat password memory by waiting 1 second and blanking the login fields, just in case you programmed your browser to remember it.

Why?  Clearly this can't be in the name of security, because you're forcing everyone to make records of their passwords.  A password like grommet would be adequate for most web sites.  It just doesn't make any sense to force people to use passwords like L9We&$KjU88.  That is a GUARANTEED breach of security policy because the user is going to write it down somewhere.

Designers take heed.  Let the users determine what passwords are secure enough.  Other than banking and medical stuff, there is nothing requiring this strong a password.

...


Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Tuesday, November 22, 2011

Reinstalling the .NET Framework on a WebServer: No Picnic


Windows SBS 2003 used as a webserver.


Ok, I was getting the same Autoupdate from Windows Update everyday, so I posted a question about it, and was advised to reinstall the .NET Framework as something had become banjaxed.

I put this off, because installing the .NET Framework (3 versions of it) had initially taken me hours.  But, being sick of the repeated updates, I finally scheduled maintenance time and went for it.

Here is the procedure that eventually worked for me to get from point A to point A (as it turns out) eating more than an entire day in the process.

Uninstall
The .NET Frameworks must be uninstalled in order, according to Microsoft, I had to guess that meant 4.0, 3.5, 2.0.  This process was handled easily from the Add/Remove Programs window, even though there are numerous blog posts out there claiming that this does not work, and there is some program out there that does it better. Regardless, here is the sequence I used.
  1. Open C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 and edit MACHINE.CONFIG. Capture the username and password, if any in the <processModel node.
  2. Open C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 and edit MACHINE.CONFIG. Capture the username and password, if any in the <processModel node.
  3. Open C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 and edit MACHINE.CONFIG. Capture the username and password, if any in the <processModel node.
  4. Stop IIS
  5. Uninstall 4.0
  6. Uninstall 3.5
  7. Uninstall 2.0
  8. Reboot

Download and Install
 Make sure when you download the new versions, that you get the FULL .NET Framework, not the "client" ones.
NOTE THAT THIS PROCESS TAKES MANY HOURS (around 12) TO COMPLETE
  1. Install 2.0
  2. Install 3.5 --This is exceedingly slow
  3. Install 4.0 --less slow than 3.5, but still... bring a book.
  4. Reboot.
  5. Let Windows update install all it's patches.--this takes a couple hours, as the 'full installs' of the .NET Framework are not the latest, they need lots of patches.
Re-register

Use this rereg.bat file to re-register all the .net frameworks
This may need to be adjusted as more frameworks come out.




This will mean you must re-enable the frameworks.
Open IIS manager, and look in Web Service Extensions.
Make sure to re-enable all the frameworks.

Now all your web sites are back, but they all give 

Server Application Unavailable


...errors.

This is because you need to re-grant your aspnet worker processes access to the server, which is off by default.  Last time this happened, you created an ASPNET user and granted him access to do his job, because some nutjob at Microsoft decided that not allowing the webserver to do anything would be more secure.

Navigate to C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 and edit MACHINE.CONFIG.
Around line 633 there is a line that looks like this: make sure the user is valid.

userName="[user]" - Windows user to run the process as.
      Special users: "SYSTEM": run as localsystem (high privilege 
admin) account.
      "machine": run as low privilege user account named "ASPNET".
      Other users: If domain is not specified, current machine name is assumed to be the domain name.

Next, Navigate to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 and edit MACHINE.CONFIG.

Around line 135 there should be a line that starts with <processModel . Make it say this...

<processModel userName="ASPUSER" password="whatever" />

... of course use the password you used to create the account.

Then go to C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319, and do the same, the <processmodel line is around line 250.

Yes, I left out 3.0 and 3.5, as they do not have a machine.config file.

Use IISRESET or just reboot the server to complete the task.

...
In my case, I still get the repeated update requests (hence the 'point A to point A' comment), but since I figured there are legitimate reasons to reinstall the framework and others might get caught in this horrible trap.  Hopefully this will save you some aneurisms.


Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Saturday, November 19, 2011

Using Return Values From Stored Procedures in C#.NET

Ok, let's say you have a stored procedure that returns a value.


Now lets say you want to test it in SQL Server Management Studio...


This gives us a value of 1, as expected.

Now if we want to call this from C#, there is a little trick we have to play with Parameters.


Note the trick we had to play here (line 19) to access the return value after the procedure runs.  At first, I tried using:
i=myCommand.ExecuteNonQuery();
...but that always yielded a value of -1.



Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Tuesday, October 18, 2011

BindingSource filters: Partial Match on Int Columns

Recently I had to do a filter on a DataGridView and needed the dataset to filter on a partial match of an integer column.   It took me a few minutes to figure this out...

if (!string.IsNullOrEmpty(ticket))
{
   filter = string.Format("Convert(ID,'System.String') like '%{0}%' ", ticket);
}
This gives a filter line that looks a lot like
"Convert(ID, 'System.String') like %123%"
 Which will show all rows where the column ID partially matches 123.


...

Bryan Valencia is a contributing editor and founder of Visual Studio Journey.  He owns and operates Software Services, a web design and hosting company in Manteca, California.

Share This!

Contact Us

Name

Email *

Message *