Pages

Tuesday, December 18, 2018

Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.

In my MVC app, I followed the OLD ASP.net roleManager and MembershipManager setup.

DO NOT DO THIS WITH MVC!

DO NOT RUN ASPNET_REGSQL!

Identity does NOT work that way anymore.

What I had to do was remove the line in my web.config that said:

    <roleManager enabled="true" cacheRolesInCookie="false"  />
Once I got rid of that, the error blessedly poofed into a memory.


...

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, December 7, 2018

Updating Object Relational Model Easily in MVC

So I got my mind around the models, if I change a field, I know how to modify the object properties to match.  Ditto the relationships - add a hashset here and there to reference linked items.
But I read the ORM (the main model page) and that thing just mystifies me.
Like this:

So a PrefCategory has many Prefs. got it.
But it has a required PrefCategory???  It requires itself? 

Anyhow, Applying the American credo just get it done, I came up with this:
To complete this tutorial you will need WinMerge.
First open up your relational mode in Models.  Copy all the text.

Open WinMerge, hit the 2 pages icon to create a new comparison,  and paste the code into the left pane.
Now in Visual Studio, create a new MVC project.  in Solution Explorer, right click Models - Add - Ado.Net Entity Model.
Choose your development database, and tick all the same tables and views you are using in your main app.
It will create all the table models.
Now open the same relational model, copy all and paste it into the right pane of WinMerge.  Hit Refresh.
Now you'll see everywhere that your code differs from what you'd see if you imported the model fresh.
In my case, I could easily see where I had an old .WithOptional that had now become a .WithRequired.  I modified my project relational model and suddenly I was no longer getting the

Multiplicity conflicts with the referential constraint in Role 'blah blah thing that doesn't exist by that name anywhere in the project' in relationship 'blah blah'. Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'.
errors.


Wednesday, November 28, 2018

SQL Server: How to Concatenate Parent Nodes in Irregular Category Trees

Consider this table:

id ParentCategory Name
1 NULL Household
2 1 Furniture
3 1 Appliances
4 2 Chair
5 2 Couch
6 2 Bed
7 3 Refridgerator
8 3 Counter
10 3 Bathroom


We want each node to display all it's parents back to its root. This SQL helps.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        bryanv
-- Create date: 11/28/2018
-- Description:    gets the whole list from here down
-- =============================================
CREATE FUNCTION dbo.CategoryFullName
(
    @CategoryID int
   
)
RETURNS nvarchar(200)
AS
BEGIN
    -- Declare the return variable here
    DECLARE @ans nvarchar(200)
    declare @parent int

    -- Add the T-SQL statements to compute the return value here
    select @ans=name, @parent=ParentCategory from Categories where id=@CategoryID

    if @parent is not null
    BEGIN
        set @ans=dbo.CategoryFullName(@parent)+' - '+@ans
    END


    -- Return the result of the function
    RETURN @ans

END
GO


This will look up the current category text, and prepend all parents recursively until it gets to the root.
 You can then use this in a computed column to autogenerate the entire category tree.

Now you can automatically get the full tree with a simple select...



...


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 20, 2018

SQL Server: Return All Dates in a Range

This function will return a list of all dates between a start date and an end date.


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        bryan valencia
-- Create date: 11/20/2018
-- Description:    returns the dates between start and end (inclusive).
-- =============================================
CREATE FUNCTION DaysBetween(@startdate DATE, @enddate DATE)
RETURNS @calendar TABLE
(
    calendarday DATE PRIMARY KEY
)
AS
BEGIN
        -- Fill the table variable with the rows for your result set

    WITH calendar AS
    (
      SELECT CAST(@startdate AS DATETIME) DateValue
      UNION ALL
      SELECT  DateValue + 1
      FROM    calendar  
      WHERE   DateValue + 1 <= @enddate
    )

    insert into @calendar(calendarday)
    (
    SELECT  cast(DateValue as Date) calendarday
    FROM    calendar
    )
    OPTION (MAXRECURSION 0)
   

    RETURN
END
GO


To call it: SELECT * FROM [dbo].[DaysBetween] ('01 jan 2018', '01 feb 2018')



...

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, September 19, 2018

css Tab Bar Demo

You created a great tabbed interface or vertical menu but you hate it that the links in the menu only respond to clicks on the actual text.

This css style info will show you how to make the whole tab clickable by making the link fill the entire box.

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="Bryan Valencia">
  <meta name="Keywords" content="Tab, bar, demo, css, html5">
  <meta name="Description" content="A quick tab bar demo showing how to make an entire div clickable instead of just the text.">
  <title>Tab Bar Demo by Bryan Valencia</title>
<style>
.tab{
width:200px;
height: 20px;
margin: 0px;
padding:10px;
text-align: center;
vertical-align: middle;
display: inline-block;
color: black;
background-color: white;
color: black;
background-color: aliceblue;
border: 1px solid silver;
border-top-right-radius: 10px;
border-top-left-radius: 10px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 0px; }
.tab:hover{
color: yellow;
background-color: green;
}
a.clickable-tab{
color: black;
display:inline-block;
width:100%; height: 100%;
vertical-align:bottom;
font-family:Arial, helvetica;
text-decoration:none;
}
.tab-bar{
display: block;
border-bottom: 1px solid silver;
padding:0px;
margin:0px;
background-color: gray;
}
</style>
 </head>
 <body>
<div class="tab-bar">
<h1>Tab Bar Demo</h1>
<div class="tab">
<a href="#" class="clickable-tab">Home</a>
</div><div class="tab">  <!-- the divs are wrapped funny here to prevent space between the tabs. -->
<a href="#" class="clickable-tab">About</a>
</div><div class="tab">
<a href="#" class="clickable-tab">Contact Us</a>
</div>
</div>
 </body>
</html>





...

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, April 26, 2018

Changelog.txt. Playing with their heads.

Today I was checking my server logs for the root IP address.  This is people who are scouring the internet by IP address looking for whatever they can find.

One file I noted a lot of 404's for was CHANGELOG.TXT.  Apparently this is a DRUPAL file that might contain the current versions of some of your server's software.

Because I like to mess with these net scanners, I created this batch file.  It creates a sparse 1 gig file full of zeroes.

What is a sparse file?  It's a compressed file that seems to be big, but only takes around 4096 bytes on the drive.

@echo off REM MakeChangeLog.bat
REM You Should place this batch file in the folder you want to create the file in.
REM You must run this batch as an administrator!
REM Note that you must have the disk space to initially create the file before it gets compressed.

fsutil file createnew changelog.txt 1000000000
fsutil sparse setflag changelog.txt
compact /c changelog.txt

pause
This resulted in a 4096 byte file on my Windows Server 2012, and a 0 byte file on my Win 10 machine.  This file STILL downloads as a 1 gig file.  You can check the file size by right-clicking CHANGELOG.TXT and selecting Properties.

One caution: Do not do this with real files like robots.txt.  This file is legitimately used by search engines to figure out what you want scanned.  You're going to burn in a very special level of Hell.  A level they reserve for child molesters, and people who talk in the theater.

Enjoy!


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, March 21, 2018

MVC: A public action method ... was not found on controller

You have a page with something embedded, a partial view, a generated image, or something.  And it's odd, but the first time you load the page, everything works, but every time you reload (like someone clicks a button on the page), MVC claims it can't find the action.

InnerException:
ErrorCode=-2147467259
HResult=-2147467259
Message=A public action method ... was not found on controller '...Controller'.
Source=System.Web.Mvc
WebEventCode=0

You check and the action is right there!.  In my case it looked like this.

//Get: ProductPartial Blocks
[HttpGet]
[AllowAnonymous]
public ActionResult ProductBlockPartial(int? ID)
{
if (ID.HasValue)
{
Product model = db.Products.Find(ID);
return PartialView(model);
}
else
{ return null; }
}

The answer, my friend, is that pesky [HttpGet].  That tells the action to only respond to get requests, and when you pushed the button to post data back to the page, it became a post.  And the post flows down from the main page to the partial view as well.
Just remove the [HttpGet] from the action and you're good as gold!

...

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.

Support

Back in the annals of history, companies wanted people to buy their software.  Most bought software came with a thing we used to call support.

Soon, places like Apple and Microsoft were getting 650 billion calls a day from every grandma that couldn't figure out how to get the cup holder to pop out.

What we really need, thought the beleaguered support operators; is a way to prevent people from accessing support. 

Support Barriers
I used to email support with a simple problem, or file a help ticket, and In the 90's I started seeing this...

I can't get the mouse to select the object in the window.

I started seeing responses like this:

Please tell us:

  • the model of your pc, 
  • the exact version of Windows, 
  • the serial number on your motherboard,
  • the embedded digital signature of your CPU
  • The exact amount of RAM, and wither it's DRAM or SRAM,
  • The exact error message you are seeing,
    • in Gaelic
  • Your exact DNA sequence,
  • and the serial number of your ISP's router.
In other words, that should get him off our backs for a while...


Expensive Support
Many things were tried.  I once had a Microsoft update eff up my web server and I waited 3 hours on hold, got a tech, and explained my problem.

His first question was, How will you be paying for this?

I won't,  I said.  You did this, not me.

Sorry, no support without payment.

OK, how much is it?

$400 to get through for 15 minutes, and there's no guarantee we will solve your problem.

But I paid over $400 for the server software to begin with!  

Sorry.  Credit card or pound sand.

I'm sure this way Microsoft could fire 80% of their foreign call center, and get back to the business of putting out flawed updates every 2 days.

Premium Support
Then came the thing where you'd pay $150 for some piece of software, and then $99 a year for premium support.  That's fine if you're using something big and mission critical, but with different support agreements on your word processing, email, databases, and on and on,  you end up paying a LOT of money every month for support.

SAAS
This is the latest in irony.  Software as a service.  It's partiucularly ironic because it contains the word service.  What SAAS means is that when you buy software, you're not buying anything.  In fact there are some packages (I'm looking at you Adobe Creative Cloud) that they want you to pay monthly for.

So all these guys who are making videos for YouTube now have to pay up monthly, while those of us who just wanted to add titles to a company presentation once, are OUT.

The truth is that you never OWNED software in the first place.  You held a limited license to use it.  If you OWNED Excel, you could sell it to someone else, or freely modify it.  It's not like a lawnmower, with which you can do what you like, it's more like paying to hear a song at a concert or a movie at a theater.  You don't OWN Star Wars because you saw it.

But I digress.

No Support
I just paid $50 for some software that made some claims on their web page, but due to a glaring BUG, it doesn't work on my machine.  I clicked support and got this:

If you have any issue with your purchase or related to the configuration of [the software], please post your request in the [user] forums, in the Troubleshooting section.
So, you fling out software, charge money, and then leave it to other users to figure out the problems by themselves?

Lawnmowers
It should be noted that anytime I have a question or problem about my lawnmower, I can still call the manufacturer.

Freeware, Shareware, Open Source
So I can fully understand why many people left the world of paid software and embraced free software.  There is usually a large user community, and you can even download it and modify it yourself (not that I would ever do that). 

The thing with open source is that there is still no support - but there is also no expectation of support.  Some small team of developers all over the world kind of run the project, and they all work for free in their mom's dank basement surrounded by Burger King and Dorito's bags.

These guys usually have Bugzilla going and they take the flurry if bugs from the clients, and choose some to rectify.  But the forums... that is a different animal.

Here's what software development looks like from a development teams point of view.


  1. You and a few friends decide that it would be cool to have an open source version of (x).
  2. Work for 3 years (for free) in every spare moment with the team to get the software where you want it.
  3. Miss your deadline and work another two years, promising that it'll be next month 24 times.
  4. Finally you get a working build (YAY)
  5. You release it to the webosphere.
  6. Here come the comments!
    1. Waited too long for crap software!
    2. It doesn't have all the features that the commercial $300 + $50 a month package has.
    3. When is it coming out for Mac?
    4. When is it coming out for Linux?
    5. It sicks. You suck. Drink bleach.
    6. I tried posting 50 messages on the forums, and no response from the team
    7. Why isn't there a Latvian version?
  7. So now you have 6,000 requests, of which there are maybe 20 real issues, and everyone thinks you can just quick-fix their thing.
    1. even though the source is open, they can download it and try to fix it at any time.
  8. Everyone gets mental when you don't release weekly bug patches.
  9. One or two people really praise it, but everyone else gripes about it.
  10. After about 2 years, no one wants to work on the project anymore, and there are no more updates.
  11. People continue to download it and fill the forums with requests, only to give up when no one 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.

Monday, March 12, 2018

How to Copy a MSSQL Server database to a New Webhost without RESTORE

This article explains how to copy a database from one server to another when Backup/Restore is not an option.

  • This will work as long as you have SQL Server Management Studio access to the source and destination databases.
  • This is very slow, and may take many hours to run on a big database.
  1. First, open the database server you want to copy in SSMS.
  2. Next, Right-click the database, Tasks -> Generate Scripts.
     
  3. In my case I want all the scripts to completely recreate my database, so here are the steps.
  4. Next
  5. Script entire database and all database objects
  6. Save to new query window (file is OK too).
  7. Click Advanced (by default it will write a script to create all objects, but not copy data).

    Make sure to select Schema and data.
  8. Review all the other settings to make sure you get the stuff you want on the destination database.  Click OK, then Next.
  9. Review and Next (or previous if you need to change something.)
  10. You'll get a checklist screen and then the script is done.  It should pop up in SSMS.
To restore the database...
  1. Log SSMS into the destination database.
  2. Back up what's there if there is any chance you'll need it.
  3. In your script, if you need to rename the database to satisfy the new hosting company, do a global replace in the SQL script.  Make sure the FileNames reflect the destination database name not the source database
  4. Copy the entire script to the clipboard.
  5. right click the destination database and do a New Query (if the database hasn't been created yet, you can click the server name).
  6. Paste the script into the new query editor.
  7. If the database already exists, you may need to delete the CREATE statement and all the ALTER DATABASE statements, down to the [USE database] command.
  8. Look in the scrollbar for possible problems...  Then fix them.
  9. Run the script and see what happens.  Get coffee.  It's gonna be a while.  Call your Dad.  He misses you.


You're done.  Just in case you don't have all the same Generate Scripts options, this demo was from a SQLExpress2016 database, using all this stuff...

Microsoft SQL Server Management Studio                        14.0.17199.0
Microsoft Analysis Services Client Tools                        14.0.1008.227
Microsoft Data Access Components (MDAC)                        10.0.16299.15
Microsoft MSXML                        3.0 4.0 6.0
Microsoft Internet Explorer                        9.11.16299.0
Microsoft .NET Framework                        4.0.30319.42000
Operating System                        6.3.16299



Thursday, February 22, 2018

Fix for nav-tabs Stop Working After jQuery Update


If your tabbed notebooks stopped working after a jQuery update then here's the fix.

First, you'll need some classes you didn't have before in your site.css


    .nav-tabs { border-bottom: 2px solid #DDD; }
    .nav-tabs > li > a {
        border: none;
        color: #666;
    }
    .nav-tabs > li.nav-item > a,
    .nav-tabs > li.nav-item > a:hover {
        border: none;
        color: #4285F4 !important;
        background: transparent;
        position: relative;
    }
    .nav-tabs > li.nav-item > a::after {
        content: "";
        background: #4285F4;
        height: 2px;
        position: absolute;
        width: 100%;
        left: 0px;
        bottom: -1px;
        transition: all 250ms ease 0s;
        transform: scale(0);
    }
    .nav-tabs > li.nav-item > a.active::after,
    .nav-tabs > li.nav-item:hover > a::after {
        transform: scale(1);
    }

    .card {
        box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.3);
    }

Then you'll need to rearrange things on your tab sets.
Use the following rules.
  1. Tabs
    1. <ul> needs to be in a <div class="nav navbar">
    2. <ul> needs <class="nav nav-tabs">
    3. <li> no longer gets class="active"
    4. <li> needs class="nav-item"
    5. <a> tags in your <li> now get class="active show" if they are the active tab.
  2. Tab Panes
    1. tab panes go in a <div class="tab-content">
    2. <div>s needs a class="tab-pane"
    3. in <div> tags, fade needs in or your div will not show.
Here is a sample page:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>
<h2>Tabsperimentation</h2>
    <div class="nav navbar-default">
        <ul class="nav nav-tabs">
            <li class="nav-item"><a class="active show" data-toggle="tab" href="#TabA">GO TO TAB A</a></li>
            <li class="nav-item"><a data-toggle="tab" href="#TabB">GO TO TAB B</a></li>
            <li class="nav-item"><a data-toggle="tab" href="#TabC">GO TO TAB C</a></li>
        </ul>
    </div>

    <div class="tab-content">
        <div id="TabA" class="tab-pane fade in active">
            THIS IS TAB A
        </div>

        <div id="TabB" class="tab-pane fade in">
            THIS IS TAB B
        </div>

        <div id="TabC" class="tab-pane fade in">
            THIS IS TAB C
        </div>
    </div>









Share This!

Contact Us

Name

Email *

Message *