mfc >> serious problems related to DLL and ODBC

by raghunandan_1081 » Tue, 28 Mar 2006 20:37:21 GMT

I have some problem with VC++ code. I have created a DLL having a
database class having connection pointer and recordset pointer. And I
have created Databse class (using ODBC) object into dllApp Class to
make it use like global object.
But when i call my dll and debug my dll i got exception at database
class destructor (while exiting fron DLL because this destructor is
called during the dll exitpoint).
//Databse.cpp
Datbase::~Database
{
newDSNptr=NULL; //_ConnectionPtr
newRECptr=NULL; //_RecordsetPtr ====>>>> Throws exception
::CoUninitialize();

}
Datbase::Database
{
::CoInitialize();
newDSNptr=NULL; //_ConnectionPtr
newRECptr=NULL; //_RecordsetPtr
try
{
newDSNptr.CreateInstance((__uuidof(Connection)));
newRECptr.CreateInstance((__uuidof(Recordset)));
newDSNptr->Open(L"Provider=MSDASQL.1;Persist Security
Info=False;DSN=NEW_DB_DSN;",L"",L"",0);
}
catch(_com_error &e)
{
AfxMessageBox(L"Error in New DataBse Connection\n" +
e.Description());
writeToFile(_T("CDatabase: ERROR: Error in New DataBse
Connection:"));
}
}
And in header file i have written like this
//Databse.h
#import "C:\Program Files\Common Files\System\ado\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")

"First-chance exception in App.exe: 0xC0000005: Access Violation."
"First-chance exception in App.exe (MSDART.DLL): 0xC0000005: Access
Violation."

I have used all the try catch block for Database member function
operation to avoid any unhandelled exception. If anybody can help me i
will be very thankful to that people. i am in serious problem plz. help
me as soon as possible.

Thanks in advance.



mfc >> serious problems related to DLL and ODBC

by Benry » Tue, 28 Mar 2006 22:11:08 GMT





Have you tried switching the order like this:
newRECptr=NULL;
newDSNptr=NULL;?

If your connection pointer is null, then your recordset pointer should
also become null.

Are you sure it's not the CoUninitialize() that's throwing the
exception? Is newRECptr a class variable, or is it local to a method?

-my one cent ( I don't have both yet)
-Benry




Similar Threads

1. Problem Related with open and close table in ODBC connection

Hello Everybody,

i have application with ms-access database in vc++(MFC).while initializing 
database with different tables and corresponding fileds,one run time error 
message would throw that table name is not found even though it works 
properly in debug mode.as well as when i add one line
Sleep(1000);
in place where table name and field name is initialized.
it goes in debug and release mode.
i want to know the reason why this problem is arrived? as sleep is very 
temporiary solution for any big application .
Any help would be appriciated.

Thanks and regards
Vibha 


2. Problem Relating NTdll.dll

3. MSAccess Problem solved (was Simultaneous access: Perl (DBD::ODBC) and C# (ODBC))

4. serious problem with linked files i VS! - CSharp/C#

5. Serious Serialization problem

I've made an inherited ListView control with a customized ColumnHeader Type. 
I've overwritten the Columns property with a collection of my custom 
ColumnHeader items. Now I would like to implement serialization so that 
columns are persisted from designtime to runtime. But I cannot get it to 
work.

I think it's because I don't know how to implement the type converter 
correctly. Here's my suggestion for the type converter. Sample code for the 
ListView, ColumnHeaderCollection and ColumnHeaderItem is supplied below. Can 
anybody tell me what's wrong?

Cheers, Johnny J.



public class MyListViewColumnConverter : TypeConverter
{
public override bool CanConvertTo
(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo 
culture, object value, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor) && value is 
MyListViewColumn)
{
MyListViewColumnitem = (MyListViewColumn)value;
ConstructorInfo ci = typeof(MyListViewColumn).GetConstructor(new Type[] 
{ });
if (ci != null)
{
return new InstanceDescriptor(ci, null, false);
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}

**********************************************************
Listview, ColumnheaderCollection, ColumnHeaderItem code:


namespace MyListView
{
public class MyListView : ListView
{
private MyColumnHeaderCollection myListViewColumnHeaders = null;
public MyListView()
{
myListViewColumnHeaders = new MyColumnHeaderCollection(this);
//Other Code
}
public MyListView(IContainer container)
{
myListViewColumnHeaders = new MyColumnHeaderCollection(this);
container.Add(this);
//Other Code
}
[Localizable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("System.Windows.Forms.Design.ColumnHeaderCollectionEditor, 
System.Design, Version=2.0.0.0, Culture=neutral, 
PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[MergableProperty(false)]
public new MyColumnHeaderCollection Columns
{
get { return myListViewColumnHeaders; }
}
//Other Code
}
[DesignTimeVisible(false)]
public class MyColumnHeaderCollection : ListView.ColumnHeaderCollection
{
private SortedList columnList = new SortedList();
public new MyListViewColumn this[int index]
{
get
{ return (MyListViewColumn)columnList.GetByIndex(index); }
}
public override ColumnHeader Add(string str, int width, HorizontalAlignment 
textAlign)
{
MyListViewColumn column = new MyListViewColumn(str, width, textAlign);
this.Add(column);
return column;
}
public override int Add(ColumnHeader column)
{
return this.Add(new MyListViewColumn(column));
}
public override void AddRange(ColumnHeader[] values)
{
for (int index = 0; index < values.Length; index++)
{
this.Add(new MyListViewColumn(values[index]));
}
}
public int Add(MyListViewColumn column)
{
int retValue = base.Add(column);
columnList.Add(column.ColumnID, column);
return retValue;
}
public new void Remove(ColumnHeader column)
{
base.Remove(column);
columnList.Remove(((MyListViewColumn)column).ColumnID);
}
public new void RemoveAt(int index)
{
ColumnHeader column = this[index];
this.Remove(column);
}
public new void Clear()
{
base.Clear();
columnList.Clear();
}
}
[DesignTimeVisible(false)]
[TypeConverter(typeof(MyListViewColumnConverter))]
public class MyListViewColumn : ColumnHeader
{
private int m_ColumnID = 0;
private static int autoColumnID = 0;
public MyListViewColumn()
{
Initialize("", 60, HorizontalAlignment.Left);
}
public MyListViewColumn(string str, int width, HorizontalAlignment 
textAlign)
{
Initialize(str, width, textAlign);
}
public MyListViewColumn(ColumnHeader column)
{
Initialize(column.Text, column.Width, column.TextAlign);
}
private void Initialize(string str, int width, HorizontalAlignment 
textAlign)
{
base.Text = str;
base.Width = width;
base.TextAlign = textAlign;
m_ColumnID = autoColumnID++;
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int ColumnID
{
get { return m_ColumnID; }
}
}
} 


6. serious encoding problem - CSharp/C#

7. serious problem with Visual C# NET

I am having a serious problem where
everytime i go to a property of an control from design view
it pops up a dialog "Arithmetic Exception: Overflow or underflow in
the arithmetic operation".

So I installed the Visual C# NET to another machine.
And the exception is gone, but instead it's showing "?????" for all
the Korean characters I put in in the page in design view.

Now I can't do anything.. here.

It worked fine before, and I didn't use Visual C# NET for a while,
then
I recently started using it again, and it's in the state that I can't
use it any more.

8. Serious not compile problem - Microsoft Visual C++/VC++