Showing posts with label dsn. Show all posts
Showing posts with label dsn. Show all posts

Monday, March 26, 2012

Problems getting information out of a SQLDataSource

I'm working in Visual Studio, I've added a SQLDataSource to the webpage which links to a SQL server database via a DSN (created with the wizard) and it brings back data from a stored procedure with no problems.

I want to access the information from this SQLDataSource in my code and can't seem to get anything from it.

help would be most appreciated.

What do you want to do with the data? Put it in a Gridview? Datalist? Here is a article with a GridView accessing a datasource.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/GridViewEx02.asp

|||I actually want to put the information into a text field rather than a datagrid.|||gave up on that and did it the easy way, all code rather than using the wizards.|||

How would you want to access the information from the SqlDataSource? If you just want to access the database retrieved from database by the Select command, you can do something like this:

SqlDataSource sds = new SqlDataSource(conn.ConnectionString, cmd.CommandText);

DataSourceSelectArguments dssa = new DataSourceSelectArguments();

dssa.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount);

DataView dv = (DataView)sds.Select(dssa);

Problems executing DML via linked server

Hey folks..
I have a linked server that connects to a DB2 database through the OLE DB
for ODBC Providers driver. I have a DSN created and can, through the linked
server run SELECT statements to my heart's content. When I want to run a
simple DELETE, for example (DELETE HCEDB.APPLQUE2), I get the following
error.
Server: Msg 7345, Level 16, State 1, Line 1
OLE DB provider 'MSDASQL' could not delete from table '"HCEDB"."APPLQUE2"'.
User did not have sufficient permission to delete the row.
[OLE/DB provider returned message: Multiple-step OLE DB operation generated
errors. Check each OLE DB status value, if available. No work was done.]
[OLE/DB provider returned message: [IBM][CLI Driver] CLI0150E Driver not
capable. SQLSTATE=S1C00]
OLE DB error trace [OLE/DB Provider 'MSDASQL' IRowsetChange::DeleteRows
returned 0x80040e21: DBROWSTATUS_E_PERMISSIONDENIED].
I have gone to a colleague's machine to use a DB2 Client and authenticated
using the same user specified in both the DSN and Linked Server and was able
to execute the DELETE. Any ideas as to cause and resolution?
Thanks..
Peace,
Gary HampsonIf you are using a DELETE FROM (Table Name), beware.
I was doing the same thing on a DB2 Database with some test data given to me
, and I would get the same error when I tried to delete using the Linked Ser
ver, where if I tried to do it straight in the DB2 Console, I could execute
without any problems.
So I ran an Event Monitor. Happens out, the Microsoft OLE DB Provider for OD
BC Drivers turns it into count(*) many "DELETE FROM TABLE WHERE field = ?".
So if your table has 1000 rows, you'll have 1000 Delete Statements run in se
quence. Very inefficent, but it gets the job done. The reason for my error w
as that there were 3 rows that were identical to each other, and so it had 3
identical "DELETE FROM" statements.
My solution: Deleted the replicated rows. It apparantly was an oversight whe
n creating the test data.
I still have an issue with it producing all those Delete Statements though.
I'm currently looking into other ways of doing it.

Friday, March 9, 2012

Problem: Can dhcp callout dll insert new row into dsn database?

I current working on this dll, but i found the dll doesn't response to any of the cdatabase execute response? I have try all the cdatabase and sql in c++ console and found that it can be run. The database is open success and the sql statement is correct.
After then i put it into the dhcp callout dll, and compile success.
When i add it into the registry and try the dhcp server, it doesn't have any response database table. And i using sql server for the dsn.
Here is my code
#include "stdafx.h"
#include "callout.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CDatabase dbCallout;

struct tm *newtime;
char am_pm[] = "AM";
__time64_t long_time;

CString strCmd, strPrimaryKey, strTime;
int nRetCode = 0;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
} return TRUE;
}

DWORD CALLBACK DhcpControlHook(DWORD dwControlCode,LPVOID lpReserved)
{
switch (dwControlCode)
{
case DHCP_CONTROL_START: {
_time64( &long_time ); /* Get time as long integer. */
newtime = _localtime64(&long_time); /* Convert to local time. */

if( newtime->tm_hour > 12 ) /* Set up extension. */
strcpy( am_pm, "PM" );
if( newtime->tm_hour > 12 ) /* Convert from 24-hour */
newtime->tm_hour -= 12; /* to 12-hour clock. */
if( newtime->tm_hour == 0 ) /*Set hour to 12 if midnight. */
newtime->tm_hour = 12;

strPrimaryKey.Format("C%.2d%.2d%.2d%.2d%.2d%.2d", newtime->tm_year - 100, newtime->tm_mon, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
strTime = asctime(newtime);

strCmd = "INSERT INTO Callout_Control (control_id, control_desc, control_date) VALUES ('" + strPrimaryKey + "', 'DHCP server have started!', '" + strTime + "')";

dbCallout.ExecuteSQL(strCmd);
dbCallout.Close();

break;
}
case DHCP_CONTROL_STOP:
{

break;
}
case DHCP_CONTROL_PAUSE:
{

break;
}
case DHCP_CONTROL_CONTINUE:
{
break;
}
}
return ERROR_SUCCESS;
}

DWORD CALLBACK DhcpServerCalloutEntry(LPWSTR ChainDlls,DWORD CalloutVersion,LPDHCP_CALLOUT_TABLE CalloutTbl)
{

CalloutTbl->DhcpAddressDelHook=DhcpAddressDelHook;
CalloutTbl->DhcpControlHook=DhcpControlHook;
CalloutTbl->DhcpDeleteClientHook=DhcpDeleteClientHook;
CalloutTbl->DhcpPktDropHook=DhcpPktDropHook;
CalloutTbl->DhcpAddressDelHook=DhcpAddressDelHook;
CalloutTbl->DhcpNewPktHook=DhcpNewPktHook;
CalloutTbl->DhcpPktSendHook=DhcpPktSendHook;

dbCallout.Open(_T("CALLOUT"), FALSE, FALSE, _T("ODBC;"));

return ERROR_SUCCESS;
}
What wrong in this code? Can dll file insert new row into dsn? Some expert please help me!!!

Hi

I think your first mitake is that :

1- In DhcpServerCalloutEntry you should set value of CalloutTbl to null if you dont impliment a function

regards

Problem: Can dhcp callout dll insert new row into dsn database?

I current working on this dll, but i found the dll doesn't response to any of the cdatabase execute response? I have try all the cdatabase and sql in c++ console and found that it can be run. The database is open success and the sql statement is correct.
After then i put it into the dhcp callout dll, and compile success.
When i add it into the registry and try the dhcp server, it doesn't have any response database table. And i using sql server for the dsn.
Here is my code
#include "stdafx.h"
#include "callout.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

CDatabase dbCallout;

struct tm *newtime;
char am_pm[] = "AM";
__time64_t long_time;

CString strCmd, strPrimaryKey, strTime;
int nRetCode = 0;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
break;
} return TRUE;
}

DWORD CALLBACK DhcpControlHook(DWORD dwControlCode,LPVOID lpReserved)
{
switch (dwControlCode)
{
case DHCP_CONTROL_START: {
_time64( &long_time ); /* Get time as long integer. */
newtime = _localtime64(&long_time); /* Convert to local time. */

if( newtime->tm_hour > 12 ) /* Set up extension. */
strcpy( am_pm, "PM" );
if( newtime->tm_hour > 12 ) /* Convert from 24-hour */
newtime->tm_hour -= 12; /* to 12-hour clock. */
if( newtime->tm_hour == 0 ) /*Set hour to 12 if midnight. */
newtime->tm_hour = 12;

strPrimaryKey.Format("C%.2d%.2d%.2d%.2d%.2d%.2d", newtime->tm_year - 100, newtime->tm_mon, newtime->tm_mday, newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
strTime = asctime(newtime);

strCmd = "INSERT INTO Callout_Control (control_id, control_desc, control_date) VALUES ('" + strPrimaryKey + "', 'DHCP server have started!', '" + strTime + "')";

dbCallout.ExecuteSQL(strCmd);
dbCallout.Close();

break;
}
case DHCP_CONTROL_STOP:
{

break;
}
case DHCP_CONTROL_PAUSE:
{

break;
}
case DHCP_CONTROL_CONTINUE:
{
break;
}
}
return ERROR_SUCCESS;
}

DWORD CALLBACK DhcpServerCalloutEntry(LPWSTR ChainDlls,DWORD CalloutVersion,LPDHCP_CALLOUT_TABLE CalloutTbl)
{

CalloutTbl->DhcpAddressDelHook=DhcpAddressDelHook;
CalloutTbl->DhcpControlHook=DhcpControlHook;
CalloutTbl->DhcpDeleteClientHook=DhcpDeleteClientHook;
CalloutTbl->DhcpPktDropHook=DhcpPktDropHook;
CalloutTbl->DhcpAddressDelHook=DhcpAddressDelHook;
CalloutTbl->DhcpNewPktHook=DhcpNewPktHook;
CalloutTbl->DhcpPktSendHook=DhcpPktSendHook;

dbCallout.Open(_T("CALLOUT"), FALSE, FALSE, _T("ODBC;"));

return ERROR_SUCCESS;
}
What wrong in this code? Can dll file insert new row into dsn? Some expert please help me!!!

Hi

I think your first mitake is that :

1- In DhcpServerCalloutEntry you should set value of CalloutTbl to null if you dont impliment a function

regards