milosev.com
  • Home
    • List all categories
    • Sitemap
  • Downloads
    • WebSphere
    • Hitachi902
    • Hospital
    • Kryptonite
    • OCR
    • APK
  • About me
    • Gallery
      • Italy2022
      • Côte d'Azur 2024
    • Curriculum vitae
      • Resume
      • Lebenslauf
    • Social networks
      • Facebook
      • Twitter
      • LinkedIn
      • Xing
      • GitHub
      • Google Maps
      • Sports tracker
    • Adventures planning
  1. You are here:  
  2. Home

There is already an open DataReader associated with this Command which must be closed first.

Details
Written by: Stanko Milosev
Category: MVC 3
Published: 12 November 2012
Last Updated: 12 November 2012
Hits: 4926
If you are receiving error message as in title, then in connection string add:

multipleactiveresultsets=True

Something like:

<add name="MyDbContext" 
connectionString="
  Data Source=myServer;Initial Catalog=MyDb;
  Persist Security Info=True;
  Integrated Security=True;
  multipleactiveresultsets=True
" />

Writing HTML Helpers

Details
Written by: Stanko Milosev
Category: MVC 3
Published: 05 August 2012
Last Updated: 05 August 2012
Hits: 5014

Writing HTML Helpers
page 330,
book Professional ASP.NET MVC 3

For example in: \MvcApplication1\MvcApplication1\Core\Extensions.cs write something like:

using System;
using System.IO;
using System.Web.Mvc;

namespace MvcApplication1.Core
{
    public static class HtmlExtensions
    {
        private class Extensions : IDisposable
        {
            private readonly TextWriter _writer;

            public Extensions(TextWriter writer)
            {
                _writer = writer;
            }

            public void Dispose()
            {
                _writer.Write("</table>");
            }
        } //private class Extensions : IDisposable

        //note that this part is not under private class Extensions : IDisposable
        public static IDisposable Begin(this HtmlHelper html)
        {
            var writer = html.ViewContext.Writer;
            writer.Write("<table>");
            return new Extensions(writer);
        }
    }
}

And in: \MvcApplication1\MvcApplication1\Views\Stanko\Index.cshtml Something like:

@using (Html.Begin())
{
}

after starting app in the HTML source I will see tag <table></table> from here

Routing

Details
Written by: Stanko Milosev
Category: MVC 3
Published: 05 August 2012
Last Updated: 05 August 2012
Hits: 4499

In Global.asax.cs RegisterRoutes change to:

public static void RegisterRoutes(RouteCollection routes)
{
	routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
	
	routes.MapRoute(
		"Default", // Route name
		"{controller}/{action}/{id}", // URL with parameters
		new { controller = "Default1", action = "Index", id = UrlParameter.Optional } // Parameter defaults
	);

}

This mean that Default1 controller will be called, action Index (also view)... It is called from:

protected void Application_Start()

and Application_Start() is place where application begans

DbContext

Details
Written by: Stanko Milosev
Category: MVC 3
Published: 05 August 2012
Last Updated: 08 January 2013
Hits: 4609

If your model look something like:

using System; 
using System.Data.Entity; 
using System.ComponentModel.DataAnnotations; 
using System.Data.Entity.Infrastructure;

namespace MvcApplication3.Models
{
    public class MyTable
    {
        [Key]
        public int MyNum { get; set; }
        public string Name { get; set; }
    }

    public class MyTableDBContext : DbContext
    {
        public DbSet MyTable { get; set; }
    }
}

Then, your connection string in Web.config must look like:

 <add name="MyTableDBContext" connectionString="Data Source=MyPC;
													Initial Catalog=MyDb;
													Integrated Security=False;
													Persist Security Info=True;
													User ID=myUser;
													Password=myPass" 
		 providerName="System.Data.SqlClient" />

Note that MyTableDBContext is in connection string and defined as DbContext in the model, and Integrated Security is false (true means to Windows Authentication)

  1. Non-identity id key
  2. Example
  3. Special characters in model
  4. Adding controller

Subcategories

C#

Azure

ASP.NET

JavaScript

Software Development Philosophy

MS SQL

IBM WebSphere MQ

MySQL

Joomla

Delphi

PHP

Windows

Life

Lazarus

Downloads

Android

CSS

Chrome

HTML

Linux

Eclipse

Page 47 of 164

  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51