.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Getting Error While storing data in database

Posted By: kamlesh     Posted Date: May 11, 2011    Points:5   Category :C#
i am using C# dot net and SQL Server 2005 but i got error

TimeOut Expired. The timeout period prior to obtaining a connection from the pool. this may have occured because all pooled connection were in use and max pool size was reached.

Please Help me ..

Responses
Author: Maverick             
Posted Date: May 12, 2011     Points: 20   

Hello,

Please specify which authentication you are using windows or sql?


Thanks,
Maverick
Author: kamlesh             
Posted Date: May 13, 2011     Points: 20   

Windows...

Thanks And Regards.
Kamlesh Nikam
Author: shiv chandra             
Posted Date: June 04, 2011     Points: 20   

Please check authentication.
If you are using LAN please make sure that you are in LAN.

Regards
Shiva
Author: kamlesh             
Posted Date: July 15, 2011     Points: 20   

private void CopyMSGData()
{
try
{
String pstFilePath = null;
List<ExportToMsg.UserInfo> lsUserInfoList = new List<ExportToMsg.UserInfo>();

ExportToMsg.ReadXMLFile(System.Environment.CurrentDirectory + "\\ExportMail.xml", ref lsUserInfoList);
for (int iUserCount = 0; iUserCount < lsUserInfoList.Count; iUserCount++)
{
ExportToMsg.strFullFolderPath = "";
ExportToMsg.strRootFolder = null;

pstFilePath = lsUserInfoList[iUserCount].strUserName;

string pstName = null;
//String strSaveFolderPath = Program.BrowseFolder;
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace outlookNs = app.GetNamespace("MAPI");

String strGUID = Guid.NewGuid().ToString();
//CLICaller.ProfileHandling(strGUID, 1,pstFilePath );

//outlookNs.Logon(strGUID, null, null, true);
outlookNs.AddStore(pstFilePath);

Microsoft.Office.Interop.Outlook.MAPIFolder rootFolder = null;
Microsoft.Office.Interop.Outlook.Stores Store1 = outlookNs.Stores;
foreach (Microsoft.Office.Interop.Outlook.Store item_Store in Store1)
{
string StoreName = item_Store.DisplayName;

if (StoreName == "Personal Folders")
pstName = "Personal Folders";
if (StoreName == "Source Folder")
pstName = "Source Folder";
if (StoreName == "Destination Folder")
pstName = "Destination Folder";
}
rootFolder = outlookNs.Stores[pstName].GetRootFolder();
Microsoft.Office.Interop.Outlook.Folders subFolders = rootFolder.Folders;

if (lsUserInfoList[iUserCount].strType1 == "Full")
{
foreach (Microsoft.Office.Interop.Outlook.Folder folder in subFolders)
{
ExportToMsg.GetSubFolders(folder, strSaveFolderPath, "", lsUserInfoList[iUserCount], 0);
}
}
else
if (lsUserInfoList[iUserCount].strType1 == "Selected")
{
for (int iFolderCount = 0; iFolderCount < lsUserInfoList[iUserCount].lsItemInfo.Count; iFolderCount++)
{
ExportToMsg.strRootFolder = lsUserInfoList[iUserCount].lsItemInfo[iFolderCount].strFolderName.Split('\\');
if (lsUserInfoList[iUserCount].strType2 == "Full")
{
foreach (Microsoft.Office.Interop.Outlook.Folder folder in subFolders)
{
if (ExportToMsg.strRootFolder[0] == folder.Name)
{
ExportToMsg.strFullFolderPath = folder.Name;
ExportToMsg.GetSubFolders(folder, strSaveFolderPath, lsUserInfoList[iUserCount].lsItemInfo[iFolderCount].strFolderName, lsUserInfoList[iUserCount], iFolderCount);
}
}
}
else if (lsUserInfoList[iUserCount].strType2 == "Selected")
{
foreach (Microsoft.Office.Interop.Outlook.Folder folder in subFolders)
{
if (ExportToMsg.strRootFolder[0] == folder.Name)
{
ExportToMsg.strFullFolderPath = folder.Name;
ExportToMsg.GetSubFolders(folder, strSaveFolderPath, lsUserInfoList[iUserCount].lsItemInfo[iFolderCount].strFolderName, lsUserInfoList[iUserCount], iFolderCount);
}
}
}

}
}
outlookNs.RemoveStore(rootFolder);
//outlookNs.Logoff();
//CLICaller.ProfileHandling(strGUID, 2,"");
}

// frmload.Close();
frmload.Close();
MessageBox.Show("Export to MSG is Completed", "Export", MessageBoxButtons.OK, MessageBoxIcon.None);
this.Close();
Process[] GetAllProcesses = Process.GetProcessesByName("OUTLOOK");
for (int i = 0; i < GetAllProcesses.Length; i++)
{
GetAllProcesses[i].Kill();
}

Thread.Sleep(200);
File.Delete(Path.GetDirectoryName(pstFilePath) + @"\~" + Path.GetFileName(pstFilePath) + ".tmp");
this.Close();

}
catch (System.Exception ex)
{
//MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
Process[] GetAllProcesses = Process.GetProcessesByName("OUTLOOK");
for (int i = 0; i < GetAllProcesses.Length; i++)
{
GetAllProcesses[i].Kill();
}
}
}


class ExportToMsg
{
public struct ItemsInfo
{
public String strFolderName;
public String strSubject;
public String strTime;
};

public struct UserInfo
{
public String strUserName;
public String strType1;
public String strType2;
public List<ItemsInfo> lsItemInfo;
};

public static String strFullFolderPath;
public static String[] strRootFolder;
public static UserInfo UserInfoList;
public static List<ItemsInfo> itemInfoList;



public static void ReadXMLFile(String strFilePath, ref List<UserInfo> lsListUserInfo)
{

XmlDocument objXMLDocument = new XmlDocument();
objXMLDocument.Load(strFilePath);

XmlNode xmlNodeValue = objXMLDocument.SelectSingleNode("/Restore/UserCount");
int iUserCounter = Int32.Parse(xmlNodeValue.InnerText);

for (int iCounter1 = 1; iCounter1 <= iUserCounter; iCounter1++)
{
UserInfo TempUserInfo = new UserInfo();

String strPathofUserMetaData = "/Restore/UserMetaData" + "[" + iCounter1 + "]";
xmlNodeValue = objXMLDocument.SelectSingleNode(strPathofUserMetaData + "/Name");
TempUserInfo.strUserName = xmlNodeValue.InnerText;

xmlNodeValue = objXMLDocument.SelectSingleNode(strPathofUserMetaData+"/Type");
TempUserInfo.strType1 = xmlNodeValue.InnerText;

if (TempUserInfo.strType1 == "Selected")
{
TempUserInfo.lsItemInfo = new List<ItemsInfo>();
xmlNodeValue = objXMLDocument.SelectSingleNode(strPathofUserMetaData + "/FolderCount");
int iFolderCount = Int32.Parse(xmlNodeValue.InnerText);

for (int iCounter2 = 1; iCounter2 <= iFolderCount; iCounter2++)
{

String strPathOfFolderMetadata = "/FolderMetaData" + "[" + iCounter2 + "]";
xmlNodeValue = objXMLDocument.SelectSingleNode(strPathofUserMetaData + strPathOfFolderMetadata + "/Name");
String strFolderName = xmlNodeValue.InnerText;


xmlNodeValue = objXMLDocument.SelectSingleNode(strPathofUserMetaData + strPathOfFolderMetadata + "/Type");
TempUserInfo.strType2 = xmlNodeValue.InnerText;

if (TempUserInfo.strType2 == "Selected")
{
xmlNodeValue = objXMLDocument.SelectSingleNode(strPathofUserMetaData + strPathOfFolderMetadata + "/MailCount");
int iMailCounter = Int32.Parse(xmlNodeValue.InnerText);

for (int iCounter3 = 1; iCounter3 <= iMailCounter; iCounter3++)
{
String strPathofMailMetadata = "/MailMetaData" + "[1]";
ItemsInfo TempItemInfo = new ItemsInfo();

TempItemInfo.strFolderName = strFolderName;

String strSubject = "/Subject" + "[" + iCounter3 + "]";
xmlNodeValue = objXMLDocument.SelectSingleNode(strPathofUserMetaData + strPathOfFolderMetadata + strPathofMailMetadata + strSubject);
TempItemInfo.strSubject = xmlNodeValue.InnerText;

String strDate = "/Date" + "[" + iCounter3 + "]";
xmlNodeValue = objXMLDocument.SelectSingleNode(strPathofUserMetaData + strPathOfFolderMetadata + strPathofMailMetadata + strDate);
TempItemInfo.strTime = xmlNodeValue.InnerText;
//TempUserInfo.lsItemInfo = new List<ItemsInfo>();
TempUserInfo.lsItemInfo.Add(TempItemInfo);
}


}
else
{
ItemsInfo TempItemInfo = new ItemsInfo();

TempItemInfo.strFolderName = strFolderName;
TempItemInfo.strSubject = "";
TempItemInfo.strTime = "";


TempUserInfo.lsItemInfo.Add(TempItemInfo);
}


}
lsListUserInfo.Add(TempUserInfo);


}
else
{
lsListUserInfo.Add(TempUserInfo);
}

}
}


public static void GetSubFolders(Folder folder, String strSaveFolderPath, String strFolderNameFromXML, UserInfo lsUserInfo, int iCounterForFolder)
{
try
{
if (strFullFolderPath == strFolderNameFromXML)
{
if (lsUserInfo.strType2 == "Selected")
{
// for (int iCounter = 0; iCounter < lsUserInfo.lsItemInfo.Count; iCounter++)
// {
Items items = folder.Items;
foreach (object item in items)
{
try
{
if (item is MailItem)
{
MailItem mailItem = item as MailItem;

if (((mailItem.Subject == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (mailItem.Subject == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && mailItem.ReceivedTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
mailItem.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}
else if (item is AppointmentItem)
{
AppointmentItem appointmentItems = item as AppointmentItem;

if (((appointmentItems.Subject == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (appointmentItems.Subject == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && appointmentItems.CreationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
appointmentItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}

else if (item is NoteItem)
{
NoteItem NotesItems = item as NoteItem;
if (((NotesItems.Subject == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (NotesItems.Subject == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && NotesItems.CreationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
NotesItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}

else if (item is TaskItem)
{
TaskItem TaskItems = item as TaskItem;

if (((TaskItems.Subject == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (TaskItems.Subject == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && TaskItems.CreationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
TaskItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}
else if (item is JournalItem)
{
JournalItem JournalItems = item as JournalItem;

if (((JournalItems.Subject == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (JournalItems.Subject == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && JournalItems.CreationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
JournalItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}

else if (item is ContactItem)
{
ContactItem ContactItems = item as ContactItem;

if (((ContactItems.FullName == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (ContactItems.FullName == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && ContactItems.CreationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
ContactItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}
}
catch (System.Exception ex)
{
clsError.LogError(ex);
}
}
// }
}
else
{
Items items = folder.Items;
foreach (object item in items)
{
try
{
if (item is MailItem)
{
MailItem mailItem = item as MailItem;
mailItem.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}
else if (item is AppointmentItem)
{
AppointmentItem appointmentItems = item as AppointmentItem;
appointmentItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}

else if (item is NoteItem)
{
NoteItem NotesItems = item as NoteItem;
NotesItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}

else if (item is TaskItem)
{
TaskItem TaskItems = item as TaskItem;
TaskItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}
else if (item is JournalItem)
{
JournalItem JournalItems = item as JournalItem;
JournalItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}

else if (item is ContactItem)
{
ContactItem ContactItems = item as ContactItem;
ContactItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}
}
catch (System.Exception ex)
{
clsError.LogError(ex);
}
}
}
}

if (folder.Folders.Count > 0)
{
Folders subFolders = folder.Folders;

foreach (Folder folder1 in subFolders)
{
try
{
if (strRootFolder == null)
{
GetNestedSubFolders(folder1, strSaveFolderPath, strFolderNameFromXML, lsUserInfo, iCounterForFolder);
}
else if (strRootFolder.Length == 1)
{
GetNestedSubFolders(folder1, strSaveFolderPath, strFolderNameFromXML, lsUserInfo, iCounterForFolder);
}
else
{
for (int iCounter = 1; iCounter < strRootFolder.Length; iCounter++)
{
if (strRootFolder[iCounter] == folder1.Name)
{
strFullFolderPath = strFullFolderPath + "\\" + folder1.Name;
GetNestedSubFolders(folder1, strSaveFolderPath, strFolderNameFromXML, lsUserInfo, iCounterForFolder);
}
}
}
}
catch (System.Exception ex)
{
clsError.LogError(ex);
}
}
}
}
catch (System.Exception ex)
{
clsError.LogError(ex);
}
}


public static void GetNestedSubFolders(Folder folder, String strSaveFolderPath, String strFolderNameFromXML, UserInfo lsUserInfo, int iCounterForFolder)
{
try
{
if (strFullFolderPath == strFolderNameFromXML)
{
if (lsUserInfo.strType2 == "Selected")
{
//for (int iCounter = 0; iCounter < lsUserInfo.lsItemInfo.Count; iCounter++)
//{
Items items = folder.Items;
foreach (object item in items)
{
try
{
if (item is MailItem)
{
MailItem mailItem = item as MailItem;

if (((mailItem.Subject == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (mailItem.Subject == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && mailItem.ReceivedTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
mailItem.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}
else if (item is AppointmentItem)
{
AppointmentItem appointmentItems = item as AppointmentItem;

if (((appointmentItems.Subject == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (appointmentItems.Subject == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && appointmentItems.CreationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
appointmentItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}

else if (item is NoteItem)
{
NoteItem NotesItems = item as NoteItem;
if (((NotesItems.Subject == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (NotesItems.Subject == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && NotesItems.CreationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
NotesItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}

else if (item is TaskItem)
{
TaskItem TaskItems = item as TaskItem;

if (((TaskItems.Subject == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (TaskItems.Subject == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && TaskItems.CreationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
TaskItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}
else if (item is JournalItem)
{
JournalItem JournalItems = item as JournalItem;

if (((JournalItems.Subject == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (JournalItems.Subject == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && JournalItems.CreationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
JournalItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}

else if (item is ContactItem)
{
ContactItem ContactItems = item as ContactItem;

if (((ContactItems.FullName == lsUserInfo.lsItemInfo[iCounterForFolder].strSubject) || (ContactItems.FullName == null && lsUserInfo.lsItemInfo[iCounterForFolder].strSubject == "")) && ContactItems.CreationTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") == lsUserInfo.lsItemInfo[iCounterForFolder].strTime)
{
ContactItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
break;
}
}
}
catch (System.Exception ex)
{
clsError.LogError(ex);
}
}
//}
}
else
{
Items items = folder.Items;
foreach (object item in items)
{
try
{
if (item is MailItem)
{
MailItem mailItem = item as MailItem;
mailItem.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}
else if (item is AppointmentItem)
{
AppointmentItem appointmentItems = item as AppointmentItem;
appointmentItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}

else if (item is NoteItem)
{
NoteItem NotesItems = item as NoteItem;
NotesItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}

else if (item is TaskItem)
{
TaskItem TaskItems = item as TaskItem;
TaskItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}
else if (item is JournalItem)
{
JournalItem JournalItems = item as JournalItem;
JournalItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}

else if (item is ContactItem)
{
ContactItem ContactItems = item as ContactItem;
ContactItems.SaveAs(strSaveFolderPath + "\\" + Guid.NewGuid().ToString() + ".msg", OlSaveAsType.olMSGUnicode);
}
}
catch (System.Exception ex)
{
clsError.LogError(ex);
}
}//end of for
}
}
if (folder.Folders.Count > 0)
{

Folders subFolders = folder.Folders;
foreach (Folder folder1 in subFolders)
{
try
{
if (strRootFolder == null)
{
GetNestedSubFolders(folder1, strSaveFolderPath, strFolderNameFromXML, lsUserInfo, iCounterForFolder);
}
else if (strRootFolder.Length == 1)
{
GetNestedSubFolders(folder1, strSaveFolderPath, strFolderNameFromXML, lsUserInfo, iCounterForFolder);
}
else
{
for (int iCounter = 1; iCounter < strRootFolder.Length; iCounter++)
{
if (strRootFolder[iCounter] == folder1.Name)
{
strFullFolderPath = strFullFolderPath + "\\" + folder1.Name;
GetNestedSubFolders(folder1, strSaveFolderPath, strFolderNameFromXML, lsUserInfo, iCounterForFolder);
}
}
}
}
catch (System.Exception ex)
{
clsError.LogError(ex);
}
}
}
}
catch (System.Exception ex)
{
clsError.LogError(ex);
}
}


Thanks And Regards.
Kamlesh Nikam


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend