EDUDOTNET

Monday, October 17, 2016

SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries'

When I try to run query with "SELECT * FROM OPENROWSET" than I`m getting error:

"Msg 15281, Level 16, State 1, Procedure GetUserData, Line 10
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', search for 'Ad Hoc Distributed Queries' in SQL Server Books Online.
"

How to make enable Ad Hoc Distributed Queries sql server 2012?

You can enable "Ad Hoc Distributed Queries" using following command:

EXEC sp_configure 'show advanced options', 1
RECONFIGURE

GO

EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE

GO


 After run the command you get the successful message :

Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.
Configuration option 'Ad Hoc Distributed Queries' changed from 0 to 1. Run the RECONFIGURE statement to install.

 
 

Friday, July 15, 2016

PayPal Refund Adaptive Chained Payment

Refund Adaptive Chained Payment

Adaptive payments handle payments between a sender of a payment and one or more receivers of the payment. You are an application owner, such as a merchant that owns a website, the owner of a widget on a social networking site, the provider of a payment application on cell phones, and so on. Your application is the caller of Adaptive Payments API operations.

How to refund adaptive chained payment in PayPal sandbox account using API & SDK?

Step: 1 Login/Register in PayPal Sandbox Account



Step: 2 after login go to Profile page by clicking on "Profile" in right side.



Step: 3 Click on "API Access" to get API signature credentials


Step: 4 go to section "API Integration" and click on API credential & you can generate API credential by clicking.



Step: 5 on this page all credentials you can copy & paste and also use in you application to integrating PayPal adaptive chained payment.


Step: 6 Make payments as per your system with adaptive chained payment





  



Refund Chained Payment
Now start refund payment process - How to refund adaptive chained payment from receivers in sandbox PayPal account

Note: - A receiver can grant you third-party access to make a refund by logging in to PayPal, choosing API Access on the Profile page, then clicking the link to Grant API permission and selecting Refund after clicking Configure a custom API authorization.
Step: 7 repeat step no. 2, 3 to continue
Step: 8 on this page click on Add/Edit API permission


Step: 9 Click on "Add new 3rd party" by clicking on it will be redirect to "Add New Third Party Permission" page



Step: 10 on this screen you can able to add/edit your 3rd party api user name and granted permission list.



Step: 11 if you want refund adaptive chained payment then you required granted permission of refund from number of receivers and click on "Save" button.


Step: 12 now you can able to refund amount of adaptive chained payment from you application page and request to PayPal with required parameters as per refund API & SDK rules. And also including number receivers with mention primary receivers & secondary receivers. All parameters are valid than refund successfully completed otherwise return result with status/error message.




Configured API/SDK in to your application using following code & parameters

For a full list of configuration parameters refer in wiki page (https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters)


Adaptive Chained Payment Process






Tuesday, May 31, 2016

Email Sending Using Gmail Account In C#

Email Sending Using Gmail Account In C#

- Following gmail smtp address is:-
- smtp.gmail.com and port:- 25, 587 - TLS
- same server and port:- 465 - SSL

- Log on using your gmail account use for sending mail and go to "Less secure apps" and turn on it. url: https://www.google.com/settings/security/lesssecureapps

- You need to enable allowing less secure apps otherwise you will get an authentication error.

- more details:- How to enable allowing less secure apps - you can follow steps mention here: https://support.google.com/accounts/answer/6010255?hl=en-GB



Below mention code for an example:

   MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress("********.**@gmail.com");
            mail.To.Add("****.xyz@gmail.com");
            mail.Subject = "Test Mail";
            mail.Body = "This is for testing SMTP mail from GMAIL";

            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential("********.**@gmail.com", "********");
            SmtpServer.EnableSsl = true;

            SmtpServer.Send(mail);


Monday, March 14, 2016

How to get javascript variable to retain value after page refresh?

This is possible to using cookies, localStorage or sessionStorage etc.

We can use localStorage for it. we need to set a varibale that should be reflected in next pages or after reload the page.
 eg.:

var myval = "xyz";

localStorage.setItem("myval", myval);


after that we can get the stored value from localStorage by page reloaded/Refresh...

like:
var myval = localStorage.getItem("myval");


The complete list of alternatives of cookies is:


  • Standard HTTP cookies
  • Local Shared Objects (Flash cookies)
  • Silverlight Isolated Storage
  • Storing cookies in RGB values of auto-generated, force-cached PNGs using HTML5 Canvas ag to read pixels (cookies) back out
  • Storing cookies in Web history
  • Storing cookies in HTTP ETags
  • Storing cookies in Web cache
  • window.name caching
  • Internet Explorer userData storage
  • HTML5 Session Storage
  • HTML5 Local Storage
  • HTML5 Global Storage
  • HTML5 Database Storage via SQLite

C# Attributes Overview [What are attributes and why do we use it?]

C# Attributes Overview


Attributes are elements that allow you to add declarative information to your programs. This declarative information is used for various purposes during run-time and can be used at design time by application development tools.

Attributes provide a powerful method of associating declarative information with C# code (types, methods, properties, and so forth). Once associated with a program entity, the attribute can be queried at run time and used in any number of ways.(msdn)

=> It’s often necessary to associate information (metadata) with types and members, e.g.
           -Documentation URL for a class
           -Transaction context for a method
           -XML persistence mapping
           -COM ProgID for a class
=> Attributes allow you to decorate a code element (assembly, module, type, member, return value and parameter) with additional information


Attributes are generally applied physically in front of type and type member declarations. They're declared with square brackets, "[" and "]", surrounding the attribute such as the following ObsoleteAttribute attribute:

[ObsoleteAttribute]

The "Attribute" part of the attribute name is optional. So the following is equivalent to the attribute above:

[Obsolete]

Deprecated:
A deprecated class or method is like that. It is no longer important. It is so unimportant, in fact, that you should no longer use it, since it has been superseded and may cease to exist in the future.

Obsolete:
The Obsolete attribute marks a program entity as one that is no longer recommended for use. Each use of an entity marked obsolete will subsequently generate a warning or an error, depending on how the attribute is configured. 

[Obsolete] attribute is a pretty useful concept in the .NET Framework, designed to mark parts of our code that is planned to be phased out and its usage should be avoided. It makes a lot of sense to mark methods or types as obsolete, e.g. when we drop support for some parts of our API and the code is planned to be removed when all the customers are migrated, or when we've restructurized our code so that there's a newer approach for particular problem and we just had no time or possibility to upgrade all the usages, etc.



For example below is a simple class where “MyFirstMethod” is decorated by the “Obsolete” attribute. So when developer call this class they are alerted that “MyFirstMethod” is obsolete and MyFirstMethod is deprecated, please use "MyFirstListMethod" instead.

Code:

namespace DemoAttributes
{
    public class MyBasicAttributesDemo
    {
        [Obsolete("MyFirstMethod is deprecated, please use MyFirstListMethod' instead")]
        public void MyFirstMethod()
        {
            //Console.WriteLine("Obsolete Attribute...");
        }

        public void MyFirstListMethod()
        {
            //Console.WriteLine("New Method...");
        }
    }

}



namespace DemoAttributes
{
    public class Program
    {
        static void Main(string[] args)
        {
            MyBasicAttributesDemo obj = new MyBasicAttributesDemo();
            obj.MyFirstMethod();
        }
    }

}








Overview & Some Attributes Description

  • Attributes are superior to the alternatives
  • Modifying the source language
  • Using external files, e.g., .IDL, .DEF

  • Attributes are extensible
  • Attributes allow to you add information not supported by C# itself

  • Not limited to predefined information

  • Built into the .NET Framework, so they work across all .NET languages
  • Stored in assembly metadata

  • Some predefined .NET Framework attributes


  • Attributes can be
  • Attached to types and members

  • Examined at run-time using reflection

  • Completely extensible
  • Simply a class that inherits from System.Attribute

  • Type-safe
  • Arguments checked at compile-time

  • Extensive use in .NET Framework
  • XML, Web Services, security, serialization, component model, COM and P/Invoke interop, code configuration etc....

Attribute Name
Description
Browsable
Should a property or event be displayed in the property window
Serializable
Allows a class or struct to be serialized
Obsolete
Compiler will complain if target is used
ProgId
COM Prog ID
Transaction
Transactional characteristics of a class











Wednesday, February 3, 2016

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


I having problem with NewtonSoft.json v4.5 when I added some package from nugget. To solve this, I ensured all my projects used the same version by running the following command and checking the results:
 try using this in web.config or app.config:

Update-Package –reinstall Newtonsoft.Json

OR

<dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json"
            publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>

</dependentAssembly>