Error :- SQL Server blocked access to STATEMENT ‘OpenRowset/OpenDatasource’ of component ‘Ad Hoc Distributed Queries’

Tags

, , ,

 

Fix :- Connect your Ms SQL database server  using SQL management studio

            Click on Submit new query and then execute following quries.

           EXEC sp_configure ‘show advanced options’, 1;

           RECONFIGURE;

          RECONFIGURE WITH OVERRIDE;

         EXEC sp_configure ‘Ad Hoc Distributed Queries’, 1;

         RECONFIGURE

 

  select *  FROM OPENROWSET(‘Microsoft.ACE.OLEDB.12.0’, ‘Excel 12.0;Database=D:\test.xlsx;’, ‘SELECT * FROM [Sheet1$]’)

Advertisements

Integrate paypal pro(do direct payment) payment getway in asp.net

string strUsername = “api user name”;
            string strPassword = “pasword”;
            string strSignature = “signature”;
            string strCredentials = “USER=” + strUsername + “&PWD=” + strPassword + “&SIGNATURE=” + strSignature;

            string strNVPSandboxServer = “https://api-3t.sandbox.paypal.com/nvp”;
            string strAPIVersion = “50.0”;
        
            string strNVP = strCredentials + “&METHOD=DoDirectPayment” +
            “&CREDITCARDTYPE=” + “credit card type”+
            “&ACCT=” + “credit card number” +
            “&EXPDATE=” + “expire date” +
            “&CVV2=” + “cvv number”+
            “&AMT=” + “100” +
            “&FIRSTNAME=” + “Gopal” +
            “&LASTNAME=” + “Singh”+
            “&IPADDRESS= ip address” +
            “&STREET=” + “street” +
            “&CITY=” + “city”+
            “&STATE=” +”state”+
            “&COUNTRY=” + “contry” +
            “&ZIP=” +”1234″ + “” +
            “&CURRENCYCODE=GBP” +
            “&PAYMENTACTION=Sale” +
            “&VERSION=” + strAPIVersion;

            try
            {
                //Create web request and web response objects, make sure you using the correct server (sandbox/live)
                HttpWebRequest wrWebRequest = (HttpWebRequest)WebRequest.Create(strNVPSandboxServer);
                wrWebRequest.Method = “POST”;
                StreamWriter requestWriter = new StreamWriter(wrWebRequest.GetRequestStream());
                requestWriter.Write(strNVP);
                requestWriter.Close();

                // Get the response.
                HttpWebResponse hwrWebResponse = (HttpWebResponse)wrWebRequest.GetResponse();
                StreamReader responseReader = new StreamReader(wrWebRequest.GetResponse().GetResponseStream());

                //and read the response
                string responseData = responseReader.ReadToEnd();
                responseReader.Close();

                string result = Server.UrlDecode(responseData);

                string[] arrResult = result.Split(‘&’);
                Hashtable htResponse = new Hashtable();
                string[] responseItemArray;
                foreach (string responseItem in arrResult)
                {
                    responseItemArray = responseItem.Split(‘=’);
                    htResponse.Add(responseItemArray[0], responseItemArray[1]);
                }

                string strAck = htResponse[“ACK”].ToString();
                Response.Write(strAck);

                if (strAck == “Success” || strAck == “SuccessWithWarning”)
                {
                    string strAmt = htResponse[“AMT”].ToString();
                    string strCcy = htResponse[“CURRENCYCODE”].ToString();
                    string strTransactionID = htResponse[“TRANSACTIONID”].ToString();
                    string strSuccess = “Thank you, your order for: $” + strAmt + ” ” + strCcy + ” has been processed.”;

                }
                else
                {
                    string strErr = “Error: ” + htResponse[“L_LONGMESSAGE0”].ToString();
                    string strErrcode = “Error code: ” + htResponse[“L_ERRORCODE0”].ToString();
            

                }
            }
            catch (Exception ex)
            {
                // do something to catch the error, like write to a log file.
                // Response.Write(“error processing”);
                //  Response.End();
             
            }

how to share a link on tiwtter

Tags

, , ,

Twitter
:

var path = “”;
var text = “”;
function ShareName(title) {
if (title == “twitter”) {
path = “http://twitter.com/share?url=”;
text = “&text=”;
ShareLink(path, text);
}
}

function ShareLink(path, text) {

var title = document.title;
title = encodeString(title);
var url = document.location;
url = encodeString(url);
var link = url + text + title;
link = path + link;
window.open(link);
return false;
}

function encodeString(text) {
var output = escape(text);
output = output.replace(“+”, “%2B”);
output = output.replace(“/”, “%2F”);
return output;
}

Import data excel to sql server in vb

Tags

, ,

Dim sSourceConstr As String = [String].Format(“Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=’Excel 12.0;'”, Server.MapPath(“Excel”) + “//” + “test.xlsx”)
Dim sDestConstr As String = ConfigurationManager.ConnectionStrings(“TestConnection”).ConnectionString
Dim sSourceConnection As New OleDbConnection(sSourceConstr)
Using sSourceConnection
Dim sql As String = String.Format(“select * from [{0}$]”, “data”)
Dim command As New OleDbCommand(sql, sSourceConnection)
sSourceConnection.Open()
Using dr As OleDbDataReader = command.ExecuteReader()
Using bulkCopy As New SqlBulkCopy(sDestConstr)
bulkCopy.DestinationTableName = “Emp”
‘You can mannualy set the column mapping by the following way.
bulkCopy.ColumnMappings.Add(“Name”, “Name”)
bulkCopy.ColumnMappings.Add(“Class”, “Class”)
bulkCopy.ColumnMappings.Add(“RollNo”, “RollNo”)
bulkCopy.WriteToServer(dr)
End Using
End Using
End Using

Import data excel to sql server

Tags

, ,

string sSourceConstr = String.Format(@”Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=’Excel 12.0;'”, Server.MapPath(“Excel”) + “//” + “test.xlsx”);
string sDestConstr = ConfigurationManager.ConnectionStrings[“TestConnection”].ConnectionString;
OleDbConnection sSourceConnection = new OleDbConnection(sSourceConstr);
using (sSourceConnection)
{
string sql = string.Format(“select * from [{0}$]”, “data”);
OleDbCommand command = new OleDbCommand(sql, sSourceConnection);
sSourceConnection.Open();
using (OleDbDataReader dr = command.ExecuteReader())
{
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sDestConstr))
{
bulkCopy.DestinationTableName = “Emp”;
//You can mannualy set the column mapping by the following way.
bulkCopy.ColumnMappings.Add(“Name”, “Name”);
bulkCopy.ColumnMappings.Add(“Class”, “Class”);
bulkCopy.ColumnMappings.Add(“RollNo”, “RollNo”);
bulkCopy.WriteToServer(dr);
}
}
}

How to add datacontext model for entity framework

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using BusinessObjects;

namespace DataLayer
{
public class DesktopSmsContext : ObjectContext
{
public DesktopSmsContext()
: base(“name=DesktopEntities”, “DesktopEntities”)
{

base.ContextOptions.ProxyCreationEnabled = false;
base.ContextOptions.LazyLoadingEnabled = true;

contacts = base.CreateObjectSet<Contact>();
contact_groups = base.CreateObjectSet<Contact_Group>();
 }

public ObjectSet<Contact> contacts { get; private set; }
public ObjectSet<Contact_Group> contact_groups { get; private set; }

 }
}

 /////////////////////////////

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GreatDevelopers.DesktopSms.BusinessObjects;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace GreatDevelopers.DesktopSms.DataLayer
{
public partial class ContactDB
{
/// <summary>
/// Adding Contact details
/// </summary>
/// <param name=”category”></param>
public static void Add(Contact contact)
{
Logger.Write(“inserting contact details from datalayer”, “DEBUG”);
using (DesktopSmsContext context = new DesktopSmsContext())
{
context.AddObject(“Contacts”, contact);
context.SaveChanges();
}
Logger.Write(“contact details added successfully from datalayer”, “DEBUG”);
}
/// <summary>
/// Updating Contact details
/// </summary>
/// <param name=”category”></param>
public static void Update(Contact contact)
{
Logger.Write(string.Format(“Updating record of contact from datalayer for id{0}”, contact.Id), “DEBUG”);
using (DesktopSmsContext context = new DesktopSmsContext())
{
Contact oldcontacts = context.contacts.First(i => i.Id == contact.Id);
context.contacts.ApplyCurrentValues(contact);
context.SaveChanges();
}
Logger.Write(string.Format(“contact record from datalayer for id{0} updated successfully”, contact.Id), “DEBUG”);
}
/// <summary>
/// deleting Contact details
/// </summary>
/// <param name=”category”></param>
public static void Delete(Contact contact)
{
Logger.Write(string.Format(“deleting record of contact from data layer for id{0}”, contact.Id), “DEBUG”);
using (DesktopSmsContext context = new DesktopSmsContext())
{
Contact selctedcontacts = context.contacts.First(i => i.Id == contact.Id);
context.contacts.DeleteObject(selctedcontacts);
context.SaveChanges();
}
Logger.Write(string.Format(“contact record deleted from data layer for id{0}”, contact.Id), “DEBUG”);
}
/// <summary>
/// Fetching Contact details by their ID
/// </summary>
/// <param name=”id”></param>
/// <returns></returns>
public static Contact GetById(int id)
{
Logger.Write(string.Format(“fetching record of contact from data layer for id{0}”, id), “DEBUG”);
using (DesktopSmsContext context = new DesktopSmsContext())
{
Contact contact = (from currentCall in context.contacts
where currentCall.Id == id
select currentCall).SingleOrDefault();
Logger.Write(string.Format(“record of contact fetched from data layer for id{0}”, id), “DEBUG”);
return contact;
}
}
}
}

public static List<Contact> GetAll()
{
Logger.Write(“fetching List of Contact from data layer”, “DEBUG”);
using (DesktopSmsContext context = new DesktopSmsContext())
{
List<Contact> contactList = null;
contactList = context.contacts.ToList();
Logger.Write(“List of Contact fetched from data layer”, “DEBUG”);
return contactList;
}
}

/// <summary>
/// Fetching List of Contact by userId
/// </summary>
/// <param name=”userId”></param>
/// <returns></returns>
public static List<Contact> GetAllByUserId(int userId)
{
Logger.Write(string.Format(“fetching all Contact for the userId{0} from datalayer”, userId), “DEBUG”);
using (DesktopSmsContext context = new DesktopSmsContext())
{
var query = from contact in context.contacts
where contact.UserId == userId
select contact;
Logger.Write(string.Format(“Fetched all Contact for the userId{0} from datalayer”, userId), “DEBUG”);
return query.ToList();
}

}

/// <summary>
/// Check Mobile Existences
/// </summary>
/// <param name=”mobile”></param>
/// <param name=”userId”></param>
/// <returns></returns>
public static bool MobileExists(string mobile, int userId)
{
Logger.Write(string.Format(“Check existence for mobile {0} from the data layer”, mobile), “DEBUG”);
bool IsExist = false;
using (DesktopSmsContext context = new DesktopSmsContext())
{
Contact contacts = (from contact in context.contacts
where contact.UserId == userId && (contact.Mobile == mobile || contact.Mobile1 == mobile || contact.Mobile2 == mobile || contact.Mobile3 == mobile)
select contact).FirstOrDefault();
if (contacts != null)
IsExist = true;
}
return IsExist;
}

/// <summary>
/// Check Mobile Existences
/// </summary>
/// <param name=”mobile”></param>
/// <param name=”userId”></param>
/// <param name=”contactId”></param>
/// <returns></returns>
public static bool MobileExistsForContact(string mobile, int userId, int contactId)
{
Logger.Write(string.Format(“Check existence for mobile {0} and contact {1} from the datalayer”, mobile, contactId), “DEBUG”);
bool IsExist = false;
using (DesktopSmsContext context = new DesktopSmsContext())
{
Contact contacts = (from contact in context.contacts
where contact.UserId == userId && (contact.Mobile == mobile || contact.Mobile1 == mobile || contact.Mobile2 == mobile || contact.Mobile3 == mobile) && contact.Id != contactId
select contact).FirstOrDefault();
if (contacts != null)
IsExist = true;
}
return IsExist;
}

/// <summary>
/// Get Contact by mobile
/// </summary>
/// <param name=”mobile”></param>
/// <returns></returns>
public static Contact GetByMobile(string mobile, int userId)
{
Logger.Write(string.Format(“Fecthing Contact Details for mobile {0} from the data manager”, mobile), “DEBUG”);
Contact contacts = null;
using (DesktopSmsContext context = new DesktopSmsContext())
{
contacts = (from contact in context.contacts
where contact.Mobile == mobile && contact.UserId == userId
select contact).FirstOrDefault();
}
return contacts;
}

How to add bookmark on pdf file using itextsharp

Add bookmarks on PDF File
  Document document = new Document(PageSize.A4, 50, 50, 25, 25);
 
            // Create a new PdfWriter object, specifying the output stream
          
            PdfWriter.GetInstance(document, new FileStream(Server.MapPath(“MyFirstPDF.pdf”), FileMode.Create));
 
            Chapter chapter1 = new Chapter(new Paragraph(“This is Chapter 1”), 1);
            Section section1 = chapter1.AddSection(20f, “Section 1.1”, 2);
            Section section2 = chapter1.AddSection(20f, “Section 1.2”, 2);
            Section subsection1 = section2.AddSection(20f, “Subsection 1.2.1”, 3);
            Section subsection2 = section2.AddSection(20f, “Subsection 1.2.2”, 3);
            Section subsubsection = subsection2.AddSection(20f, “Sub Subsection 1.2.2.1”, 4);
            Chapter chapter2 = new Chapter(new Paragraph(“This is Chapter 2”), 1);
            Section section3 = chapter2.AddSection(“Section 2.1”, 2);
            Section subsection3 = section3.AddSection(“Subsection 2.1.1”, 3);
            Section section4 = chapter2.AddSection(“Section 2.2”, 2);
            chapter1.BookmarkTitle = “Changed Title”;
            chapter1.BookmarkOpen = true;
            chapter2.BookmarkOpen = true;
            document.Add(chapter1);
            document.Add(chapter2);
            // Add the Paragraph object to the doc

Check Adobe Reader is installed or not (c#)

using namespage using Microsoft.Win32;

you can check  adobe reader installed or not in your system 

RegistryKey adobe = Registry.LocalMachine.OpenSubKey(“Software”).OpenSubKey(“Adobe”);
if (adobe != null)
{
RegistryKey acroRead = adobe.OpenSubKey(“Acrobat Reader”);
if (acroRead != null)
{
Process.Start(“Enter your application name here”);
}
}
else
{
System.Windows.MessageBox.Show(“Please install acrobat reader for viewing PDF”, “Information Message”, MessageBoxButton.OK, MessageBoxImage.Information);
}

How to create pdf file using iTextSharp

add reference of iTextSharp dll in your project.

you can download iTextsharp dll from http://sourceforge.net/projects/itextsharp/

Document document = new Document(PageSize.A4, 50, 50, 25, 25);

// Create a new PdfWriter object, specifying the output stream

var output = new FileStream(Server.MapPath(“MyFirstPDF.pdf”), FileMode.Create);

PdfWriter.GetInstance(document, output);

// Open the Document for writing

document.Open();

… Step 3: Add elements to the document! …

Paragraph welcomeParagraph = new Paragraph(“Hello, World!”);

// Add the Paragraph object to the document

document.Add(welcomeParagraph);

// Close the Document – this saves the document contents to the output stream

document.Close();

Quote

How to add header and footer on pdf file using iTextSharp

first we create a class that in inherited by  PdfPageEventHelper and  i create a table in this class for footer content.

public partial class Footer : PdfPageEventHelper

{

public override void OnEndPage(PdfWriter writer, Document doc)

{

Paragraph footer= new Paragraph(“THANK YOU”, FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));

footer.Alignment = Element.ALIGN_RIGHT;

PdfPTable footerTbl = new PdfPTable(1);

footerTbl.TotalWidth = 300;

footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;

PdfPCell cell = new PdfPCell(footer);

cell.Border = 0;

cell.PaddingLeft = 10;

footerTbl.AddCell(cell);

footerTbl.WriteSelectedRows(0, -1, 415, 30, writer.DirectContent);

}

}

after this

Document document = new Document(PageSize.A4, 50, 50, 25, 25);

var output = new FileStream(Server.MapPath(“Demo.pdf”), FileMode.Create);

PdfWriter writer = PdfWriter.GetInstance(document, output);

// Open the Document for writing

document.Open();

//using footer class

writer.PageEvent = new Footer();.

Paragraph welcomeParagraph = new Paragraph(“Hello, World!”);

document.Add(welcomeParagraph);

document.Close();