Advertisements

Archive

Archive for the ‘Tips & Tricks’ Category

EF code first – Model compatibility cannot be checked because the database does not contain model metadata

October 10, 2017 Leave a comment

This suggests that migration table is out of sync (even if your data isn’t), and that’s been part of the db schema now (since 4.3 I think – under system tables).

There could be many reasons and ways to experience that error , but most of the time…

The problematic part is some combination of manually backing/restoring the full database with code changes alongside – I’m not entirely certain as to why always.

In short, even if Db-s are the same migration table data might not be – and hash comparison may fail (still full restore sounds like good enough – but you have ‘two sides’).

What works for me is to use
Update-Database -Script

That creates a script with a ‘migration difference’,
which you can manually apply as an SQL script on the target server database (and you should get the right migration table rows inserted etc.).

If that still doesn’t work – you can still do two things…

a) remove the migration table (target – under system tables) – as per http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-automatic-migrations-walkthrough.aspx comments in there – that should fail back to previous behavior and if you’re certain that your Db-s are the same – it’s just going to ‘trust you’,

b) as a last resort I used – make a Update-Database -Script of the full schema (e.g. by initializing an empty db which should force a ‘full script’),
find the INSERT INTO [__MigrationHistory] records,
just run those, insert them into the database,
and make sure that your databases – and code match,

that should make things run in sync again.

(disclaimer: this is not a bullet proof to work at all times, you may need to try a few things given your local scenarios – but should get you in sync)

Also this will work

I found the code will work by changing

static LaundryShopContext()
{
Database.SetInitializer<LaundryShopContext>(
new DropCreateDatabaseIfModelChanges<LaundryShopContext>());
}
into

static LaundryShopContext()
{
Database.SetInitializer<LaundryShopContext>(
new DropCreateDatabaseAlways<LaundryShopContext>());
}

 

Advertisements

GridView: Findcontrol from HeaderTemplate/ItemTemplate

September 19, 2017 Leave a comment

How to find item template control in GridView?

Dim chkHeader As CheckBox = DirectCast(gridView1.Row.FindControl(“chkHeader”), CheckBox)

How to find control from header template in grid view?

For example If you want to find checkbox available in header template of gridview

<asp:GridView ID=”gridView1″ runat=”server” AutoGenerateColumns=”False”><Columns>

<asp:TemplateField >

<HeaderTemplate>

<asp:CheckBox ID=”chkHeader” runat=”server” />

 </HeaderTemplate>

</asp:TemplateField >

</Columns>

</asp:GridView>

Solution:

Find Header control using following line of code

VB.NET Code:

Dim chkHeader As CheckBox = DirectCast(gridView1.HeaderRow.FindControl(“chkHeader”), CheckBox)

C# Code:

CheckBox chkHeader = (CheckBox)gridView1.HeaderRow.FindControl(“chkHeader”);

Hope this is help !

 

 

 

 

 

Cross-Domain requests in Javascript

August 28, 2017 Leave a comment

jvaneyck

If you are developing a modern web-based application, chances are you:

  1. Are using javascript on the client side.
  2. Need to integrate with services that are not completely under your control (or that reside in a different “origin”).
  3. Have been confronted by this error message in your browser’s console:

XMLHttpRequest cannot load http://external.service/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://my.app' is therefore not allowed access.

Every time I need to integrate a web app with some external service or some server-side API I have no complete control over, I bump into this error. Google has not yet provided me with a concise description of the problem or an overview of alternatives to perform Cross-Domain requests, so this post will serve as a personal future reference.

View original post 1,911 more words

Categories: Tips & Tricks

UpdatePanel and triggers from a repeater control


If you want to backstop on some controls click you must need to specify triggers in UpdatePanel

For example:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
   <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
     <ItemTemplate>
       <%# Eval("Name") >%>
       <asp:Button ID="Button1" runat="server" Text="Button" />
      </ItemTemplate>
    </asp:Repeater>
 </ContentTemplate>
<Triggers>
   <asp:PostBackTrigger ControlID="Buton1" />
</Triggers>
</asp:UpdatePanel>

You will face following error message with above code

A control with ID ‘Button1’ could not be found for the trigger in UpdatePanel ‘UpdatePanel1’.

Here is simple solution for above problem

 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
  <ItemTemplate>
 <!--when cick the button1, it will fire the btnDummy-->
   <asp:Button ID="Button1" Text="Click"
   OnClientClick="$get('btnDummy').click();return false;"
   runat="server" />
  </ItemTemplate>
 </asp:Repeater>

 <!--Make a hidden button to treat as the postback trigger-->
 <asp:Button ID="btnDummy" runat="server" Style="display: none" Text="HiddenButton" />

Send Email from a Static HTML

April 29, 2017 9 comments

Send an email without back-end/server side code.

There are many solutions available for sending an email here I am explaining steps to sending an email from html page using Google Apps mail.

1. Make a Copy of the Sample Spreadsheet.

Sample: https://docs.google.com/spreadsheets/d/1Bn4m6iA_Xch1zzhNvo_6CoQWqOAgwwkOWJKC-phHx2Q/

1

2.Open the Script Editor

Open the Script editor… by clicking “Tools” > “Script editor…

3

3. Set the TO_ADDRESS in the Script

4

4. Save a New Version of your Script

Goto File-> Manager Version option to set Version

5. Publish the Updated Script as a Web App

Goto menu Publish-> Deploy as Web app option to publish

Select the latest project version to deploy:

7

6. Authorize the Script to Send Emails

Click Continue to authorize this app

8

Copy the web app URL to your clip board / note pad. Then Click “OK”.

10

7. Create your basic HTML Form

11

8. Open the HTML Form (page) in your Browser

Fill in some sample data in the HTML Form:

12

Submit the form. You should see a confirmation that it was sent like

{“result”:”success”,”data”:”{\”color\”:[\”\”],\”name\”:[\”Rahul\”],\”message\”:[\”This is test \”],\”email\”:[\”rahulgbhatia@live.com\”]}”}

Alternate solution : Use Ajax to submit the form

Hope this help !

Background Reading

 

Unable to launch the ASP.NET Development server because port ‘1900’ is in use


The Problem

You are coding away, Visual Studio locks up for one of it’s many reasons, and reopen your project and run it again. You then get the “Unable to launch the visual studio development server because port 9452 is in use” error

The Cause

When Visual Studio crashed, the Web Server did not, so basically it thinks you are trying to run two instances at the same time, which is not allowed.

The Solution

Open up the process manager, go to the Processes tab, and select “WebDev.WebServer40.exe” and click “End Process”. Then try running your project again. Visual Studio will now start the project fresh and the problem should go away.

1

Or try this

2jpg

 

Hope it helps !

Pound Symbol

November 7, 2012 Leave a comment

To type pound symbol press ALT + 0163

Categories: Tips & Tricks