Monday 31 January 2011

Send Mail Using MS Access Forms and VB6

 

Use DoCmd.SendObject

The SendObject method carries out the SendObject action in Visual Basic.
DoCmd.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)

ObjectType - Optional AcSendObjectType.
AcSendObjectType - Can be one of these constants.

acSendDataAccessPage
acSendForm
acSendModule
acSendNoObject default
acSendQuery
acSendReport
acSendTable

ObjectName - An optional string variant expression that's the valid name of an object of the type selected by the objecttype argument.

New! Download Access example of the Sendobject Method

If you want to include the active object in the Email message, specify the object's type with the objecttype argument and leave this argument blank. If you leave both the objecttype and objectname arguments blank (the default constant, acSendNoObject, is assumed for the objecttype argument), Microsoft Access sends a message to the Email application without an included database object. If you run Visual Basic code containing the SendObject method in a library database, Microsoft Access looks for the object with this name first in the library database, then in the current database.
OutputFormat - Optional Variant.
To - An optional string expression that lists the recipients whose names you want to put on the To line in the E-mail message. Separate the recipient names you specify in this argument and in the cc and bcc arguments with a semicolon (;) or with the list separator set on the Number tab of the Regional Settings Properties dialog box in Windows Control Panel. If the recipient names aren't recognized by the Email application, the message isn't sent and an error occurs. If you leave this argument blank, Microsoft Access prompts you for the recipients.
Cc - An optional string expression that lists the recipients whose names you want to put on the Cc line in the mail message. If you leave this argument blank, the Cc line in the mail message is blank.
Bcc - An optional string expression that lists the recipients whose names you want to put on the Bcc line in the mail message. If you leave this argument blank, the Bcc line in the mail message is blank.
Subject - An optional string expression containing the text you want to put on the Subject line in the mail message. If you leave this argument blank, the Subject line in the mail message is blank.
MessageText - An optional string expression containing the text you want to include in the body of the mail message, after the object. If you leave this argument blank, the object is all that's included in the body of the mail message.
EditMessage - Optional  - use True (–1) to open the electronic mail application immediately with the message loaded, so the message can be edited. Use False (0) to send the message without editing it. If you leave this argument blank, the default (True) is assumed.
TemplateFile - Optional string expression that's the full name, including the path, of the file you want to use as a template for an HTML file.

 

 

Ex:

DoCmd.SendObject acSendReport , "Sales By Order", acFormatRTF , "To@gmail.com", "Cc@gmail.com", "Bcc@gmail.com","Subject", "Message", False   

The SendObject method provides a way to send a MAPI mail message programmatically in Microsoft Access. However, the SendObject method does not give you access to complete mail functionality, such as the ability to attach an external file or set message importance. The example that follows uses Automation to create and send a mail message that you can use to take advantage of many features in Microsoft Outlook that are not available with the SendObject method.

 

Use Oulook

Add a reference to the vb project:

  1. On the Tools menu, click References.
  2. In the References box, click the Microsoft Outlook 10.0 Object Model and then click OK.

Private Sub UsingOutLook()
    Dim objOutlook As Outlook.Application
    Dim objEmail As Outlook.MailItem
    '***creates an instance of Outlook
    Set objOutlook = CreateObject("Outlook.Application")
    Set objEmail = objOutlook.CreateItem(olMailItem)
    Dim toEmail As String
    Dim Content As String
    Content = "Hi, How Are You?"
    toEmail = "lakshmidupati@utdgroup.com"
    '***creates and sends email
    With objEmail
        .To = toEmail
        .subject = "Mail From MS Access"
        ‘.Body = “Anything” 
‘Use this if body doesnt contain any html tags.
        .BodyFormat = olFormatHTML
        .HTMLBody = "<html><br/>Hi<br/>Your Message</html>"
        .Send
'sends the email in Outlook.  Change to DISPLAY if you want to be able to
                      'modify or see what you have created before sending the email
    End With
    '**closes outlook
    objOutlook.Quit
    Set objEmail = Nothing
End Sub

 

 

Use SMTP

 

Dim myMail As New MailMessage()
myMail.From = "from@gmail.com"
myMail.To = "to@gmail.com"
myMail.Subject = "SMTP Mail"
myMail.Priority = MailPriority.Low
myMail.BodyFormat = MailFormat.Html
myMail.Body = "<html><body>SMTP Mail- success</body></html>"
Dim myAttachment As New MailAttachment("c:\attach\attach1.txt", MailEncoding.Base64)
myMail.Attachments.Add(myAttachment)
SmtpMail.SmtpServer = "MyMailServer"
SmtpMail.Send(myMail)


Friday 14 January 2011

WCF Errors

 

Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.Serialization.SerializationException: Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota.
Source Error:

Line 6:          Dim obj As New PublicSchemeLibrary.SchemeClass()
Line 7: Dim currdate As DateTime = DateTime.Now
Line 8: Response.Write("<HTML><HEAD></HEAD><BODY>" + obj.GetSchemes() + "</BODY></HTML>")
Line 9: Response.Write(ControlChars.NewLine)
Line 10: Response.Write(Environment.NewLine)


Source File: c:\inetpub\wwwroot\UI\Schemes.aspx.vb    Line: 8


Stack Trace:





[SerializationException: Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. ]
System.Runtime.Serialization.XmlObjectSerializerContext.IncrementItemCount(Int32 count) +199
ReadMBPublicSchemeSummaryFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] ) +630
System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context) +83
System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) +39
System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract) +1730
System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns) +74
ReadArrayOfMBPublicSchemeSummaryFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString , XmlDictionaryString , CollectionDataContract ) +214
System.Runtime.Serialization.CollectionDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context) +220
System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) +39
System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract) +1730
System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns) +66
System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName) +1042
System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName) +416
System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName) +66
System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest) +152

[NetDispatcherFaultException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:objSchemes. The InnerException message was 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota. '. Please see InnerException for more details.]
PublicSchemeLibrary.SchemeClass.GetSchemes() in C:\Documents and Settings\lakshmidupati\My Documents\Visual Studio 2005\Projects\UI\PublicSchemeLibrary\SchemeClass.vb:285
Schemes.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\UI\Schemes.aspx.vb:8
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2603


 



Solution :



http://www.devx.com/dotnet/Article/38407/1763/page/2



4. Change the max buffer size and max received message size (if needed).


At run time you may encounter two errors related to the amount of data being served by the server:




  1. The maximum message size quota for incoming messages (65536) has been exceeded.


  2. Maximum number of items that can be serialized or deserialized in an object graph is '65536'.



WCF limits the amount of data you can send over the wire per call to 64K, which is why the first error occurs. If your endpoint has methods that return more data than that (such as a collection), you have to change the buffer size and max received size from 64K to a suitable number.



If you add a service by using the add service reference option, the values added on the server won't always reflect on the client. The client always defaults to 64K, which can cause a lot of confusion if many developers are changing the client configuration. A binding value that is updated on the server will have to be changed again on the client.



To fix the second error mentioned above, you can add the following element to the client config file in the service behavior section (2147483647 is used as an example only):



 


<dataContractSerializer maxItemsInObjectGraph="2147483647" /> 


 



 



Fisrt we must add a section to our app.config servicemodel  : endpoint behavior:




    <behaviors>

      <endpointBehaviors>


        <behavior name="Graph">


          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>


        </behavior>


      </endpointBehaviors>


    </behaviors>




Then at your endpoint you can reference it:



<client>



<endpoint address=http://DomainName/PublicScheme/default.svc


          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPublicScheme"


          contract="WCF_PublicScheme.IPublicScheme" name="BasicHttpBinding_IPublicScheme" behaviorConfiguration="Graph"/>


    </client>



It should solve the problem.

Tuesday 11 January 2011

Useful Commands from Command Prompt :

 

To Flush/Refresh the Cache

Z:\>ipconfig /flushdns

Windows IP Configuration

Successfully flushed the DNS Resolver Cache.

Z:\>ipconfig /flushdns

 

SVCUTIL to get metadata of a service

C:\Program Files\Microsoft Visual Studio 8\VC>svcutil /t:metadata http://utdws109/MBPublicScheme/default.svc?wsdl

Cannot obtain Metadata from http://IPAddress/Service/default.svc?wsdl ----DNS Settings

C:\Program Files\Microsoft Visual Studio 8\VC>svcutil /t:metadata http://192.168.1.51/MBPublicScheme/default.svc?wsdl
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.30]
Copyright (c) Microsoft Corporation. All rights reserved.

Attempting to download metadata from 'http://192.168.1.51/MBPublicScheme/default.svc?wsdl' using WS-Metadata Exchange or DISCO.
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.30]
Copyright (c) Microsoft Corporation. All rights reserved.

Error: Cannot obtain Metadata from http://192.168.1.51/MBPublicScheme/default.svc?wsdl

If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata pu
blishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.mic
rosoft.com/fwlink/?LinkId=65455.


WS-Metadata Exchange Error
URI: http://192.168.1.51/MBPublicScheme/default.svc?wsdl

Metadata contains a reference that cannot be resolved: 'http://192.168.1.51/MBPublicScheme/default.svc?wsdl'.

Content Type application/soap+xml; charset=utf-8 was not supported by service http://192.168.1.51/MBPublicScheme/default.svc?w
sdl. The client and service bindings may be mismatched.

The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=
utf-8' was not the expected type 'text/xml; charset=utf-8'..


HTTP GET Error
URI: http://192.168.1.51/MBPublicScheme/default.svc?wsdl

The document was understood, but it could not be processed.
- The WSDL document contains links that could not be resolved.
- There was an error downloading 'http://s2-utdsrv07/MBPublicScheme/default.svc?xsd=xsd0'.
- The remote name could not be resolved: 's2-utdsrv07'

If you would like more help, type "svcutil /?"




Solution :

I did added the IpAddress of the machine to the DNS Manager and it worked fine for me.

If you want to use IPAddress of the machine instead of machine name in wsdl file :

Go to IIS..


Right Click on Default Website --> Edit Binings --> Host Name : IP Address of the Machine.


Or
Go to C:\WINDOWS\system32\drivers\etc\hosts.txt file
and add an entry for the machine and IPAddress.

Monday 10 January 2011

WCF, Service attribute value in the ServiceHost directive could not be found.

I'm trying to host my service with IIS 7 but I keep get this exception.
Server Error in '/WebServices' Application.
--------------------------------------------------------------------------------

Server Error in '/' Application.
--------------------------------------------------------------------------------

The type 'PublicScheme.PublicScheme', provided as the Service attribute value in the ServiceHost directive could not be found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The type 'MBPublicScheme.PublicScheme', provided as the Service attribute value in the ServiceHost directive could not be found.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidOperationException: The type 'PublicScheme.PublicScheme', provided as the Service attribute value in the ServiceHost directive could not be found.]
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +830
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +779
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +46
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +683

[ServiceActivationException: The service '/myservice/Default.svc' cannot be activated due to an exception during compilation. The exception message is: The type 'MBPublicScheme.PublicScheme', provided as the Service attribute value in the ServiceHost directive could not be found..]
System.ServiceModel.AsyncResult.End(IAsyncResult result) +460
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +471
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +276
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +220
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4952; ASP.NET Version:2.0.50727.4955


Solution:

This message is often due to an IIS 7 config problem. If you are used to creating a virtual directory pointing to the folder where your service resides, that no longer works. Now, you need to use the "Create Application..." option instead.

IIS7: WCF Services - .SVC do not work

I came across a problem with Windows Communication Foundation Services and IIS 7.
I deployed a .SVC file to my IIS 7.
The service worked during development on the local ASP.NET Dev Web server, but after deploying it to the server, there was an error:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
The configuration section 'system.serviceModel' cannot be read because it is missing a section declaration.
After some research on Google someone suggested me to Install and register .NET3.0 with IIS7.
Execute the following command
"%WINDIR%\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe" -i

http://blogs.msdn.com/b/knom/archive/2009/10/14/iis7-wcf-services-svc-do-not-work.aspx