|
Hi,
I'm writing an windows application that access SQL SERVER database. But I have a problem when trying to run the program in a computer which has an internet connection with dynamic IP, it can't connect to the SQL database.
Is anyone have solutions for this problem?
thanks b4
|
|
|
|
|
i`m looking information about progress database, anybody ever use it? What kind of database is it? I`ve look it at google, but couldn`t find what I need. Thanks
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
|
Hi all,
Help – to be honest I’m not sure if this is an oracle question or a .net one, I am trying to invoke a job in my oracle 9i db from a web app. The job is created fine and runs fine when scheduled in oem. However I want to run the job from my vb.net web app. I have imported a dll, oemjobcreator, and invoked the Run command passing in what I believe to be the correct parameters but the job does not run. How do I invoke the job, or define the schedule from code? Has anyone tackled the problem of invoking oracle jobs from code?
Cheers,
Rob
|
|
|
|
|
I'm trying to insert a Hashtable in my database, and the way I found was first to serialize the Hashtable to a file before inserting the file (as a BLOB) into the database.
Is there a direct way to do this? That instead of going Object->File->BLOB, I can go from Object to BLOB directly.
Rafferty
|
|
|
|
|
Depends what your programming platform is. For instance, in C++ using OLE DB, you could serialise to an IStream object (or to memory and then create a stream on it), and use the IStream object directly from the provider...
Steve S
Developer for hire
|
|
|
|
|
oh yeah.. i'm using C#
I thought of a way that I'm not sure if it's going to work. This is how it goes:
- use the MemoryStream class
- Serialize the HashTable object to it using the BinaryFormatter.Serialize(...)
- Then convert this to type byte[] (the size of the byte array is based on the MemoryStream.Length <-- this is what I'm not sure of if this will work). Any feedbacks?
Thank you,
Rafferty
|
|
|
|
|
Can't help you, I'm afraid. I've used C++ almost exclusively for that kind of stuff. However, it sounds like it should work, since it's similar to what I've done. Presumably you have some way of writing arbitrary binary data to the db, specifying the data (your byte []) and the length, in which case, there's no reason to suppose it won't work.
Steve S
Developer for hire
|
|
|
|
|
I'll try to summarize what i did for inserting and for retrieving the BLOBs in a pseudo-code level...
object obj1;<br />
object obj2;<br />
object obj3;<br />
<br />
InsertData()<br />
{<br />
MemoryStream stream = new MemoryStream();<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
<br />
Hashtable ht = new Hashtable();<br />
ht.Add( "Object1", obj1 );<br />
ht.Add( "Object2", obj2 );<br />
ht.Add( "Object3", obj3 );<br />
<br />
formatter.Serialize( stream, ht );<br />
<br />
int iStreamLength = Convert.ToInt32(stream.Length);<br />
byte[] byteBackup = new byte[iStreamLength];<br />
stream.Read( byteBackup, 0, iStreamLength );<br />
stream.Close();<br />
<br />
SqlConnection conn = new SqlConnection( strConnectionString );<br />
SqlCommand cmd = new SqlCommand( "ins_BackupData", conn );<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.Parameters.Add( "@Name", "ObjectsBackup" );<br />
cmd.Parameters.Add( "@Data", byteBackup );<br />
<br />
cmd.ExecuteNonQuery();<br />
}<br />
<br />
RetrieveData()<br />
{<br />
SqlConnection conn = new SqlConnection( strConnectionString );<br />
SqlCommand cmd = new SqlCommand( "get_BackupData", conn );<br />
cmd.CommandType = CommandType.StoredProcedure;<br />
cmd.Parameters.Add( "@Name", "ObjectsBackup" );<br />
<br />
conn.Open();<br />
<br />
object obj = cmd.ExecuteScalar();<br />
<br />
if( obj != null )<br />
{<br />
byte[] byteBackup = (byte[])obj;<br />
MemoryStream stream = new MemoryStream(byteBackup);<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
<br />
Hashtable ht = (Hashtable)formatter.Deserialize( stream );<br />
obj1 = ht["Object1"];<br />
obj2 = ht["Object2"];<br />
obj3 = ht["Object3"];<br />
<br />
stream.Close();<br />
}<br />
}
But in retrieving the data I'm getting this error, so clearly there's something wrong. I wonder if it's with the insertion or retrieval or both.
ERROR:
Binary stream does not contain a valid BinaryHeader, 0 possible causes, invalid stream or object version change between serialization and deserialization.
Any ideas? did I deserialize this incorrectly?
|
|
|
|
|
Hi
Frankly speaking, what ever one says, Microsoft technologies will always remain problem-matic.. specially with versions... they don have seamless integration. Deployment is always always an issue. But I still love .NET!! Anyway folks, my problem goes like this...
I am reading and updating excel sheet using ADO .NET.
Everything is working fine on machine, but on server it is all messing up...
I connect to sheet using the string called...
Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=YES;'
But whenver I try to execute insert command, following error occurs...
Operation must use an updateable query.Microsoft JET Database Engine at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at MyPledge.ClientPaymentData.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Web1\Data.aspx.vb:line 74
I will highly appreciate if someone help me... !!!
eff_kay
-------------------
Therez No Place like ... 127.0.0.1
|
|
|
|
|
Hi
Presently i'm working in VB.Net with Oracle 9i as Backend. I need to
insert a bulk of records with two columns one as varchar and other as
number.Need to call a procedure with string array and number array as
input parameter, where i could go for inserting into Table instead of
calling reader from codebehind class as number of times the array length.
Thanks in advance for you replies
|
|
|
|
|
I am trying to import records in a Access Database. Each time I run this code, the records are added to my database, BUT it adds to the existing database. Example if I run code once, it imports 100 records, the next time I run the code again, it imports another 100 records. Now my Access database has 200 records, when it should only have 100 records. Can anyone help me on this? Thanks
Private Sub ImportToAccess()
Dim Con1 As New ADODB.Connection
Dim Con2 As New ADODB.Connection
Dim mySQL1 As String
Dim mySQL2 As String
Dim myDSN As String
Dim mySET As String
Dim tmpTable As String
'Connection parameters for Source Database
myDSN = "DSN=Springbrook1;UID=suresh;PWD=nissan;"
mySET = "set schema 'pub'"
mySQL2 = "select * from customer"
'Open Source Database
Con2.Open myDSN
Con2.Execute (mySET)
'Open Destination Database
Con1.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Temp\VB Sample Codes\mcwd\Connect Program\test1.mdb;" & _
"Jet OLEDB:Engine Type=5;"
'WORKS BUT CREATES DUPLICATE RECORDS
'mySQL1 = "INSERT INTO [C:\Temp\VB Sample Codes\mcwd\Connect Program\test1.mdb].[tblCustomer] SELECT Cust_No, First_Name FROM [odbc;DSN=Springbrook1;UID=suresh;PWD=nissan;].[Customer]"
Con1.Execute mySQL1
Con1.Close
Con2.Close
Set Con1 = Nothing
Set Con2 = Nothing
End Sub
|
|
|
|
|
If your intention is to replace the existing set of records with the new set, then execute a delete statement before executing your insert statement... something like this:
Con1.Execute "DELETE FROM tblCustomer"
|
|
|
|
|
Since the table has linked information, Can I not use any other SQL statement to update the information into my table. Using the delete statement will empty my table before importing new records. Any other ways to update instead of delete?
Thanks
|
|
|
|
|
Hi there. Well, sure, you could use the sql UPDATE statement to modify existing records. In your circumstance, you may wish to write code that selects the set of records from your source, then loop through that set issuing UPDATE statements for each record to modify the data.
|
|
|
|
|
Mike:
Does that mean I need a SELECT statement, than a loop to read records, and than a UPDATE statement to modify the records? How do I SELECT and read the records on temporary basis to compare the data?
|
|
|
|
|
I am trying to load very large amounts of data into a table (Access for now, SQL server later) from a C++/ADO application. There are about 200,000 rows consisting of 7 columns, all numbers. I have used the regular ADO RecordSet object AddNew method (~15 minutes), same but disconnecting and then reconnecting the RecordSet with a batch update (~5 minutes), and finally creating a SQL INSERT statement for direct execution (~5 minutes). I have removed most indexes on the database to facilitate insertions.
Is there a faster way to do this? Given that the computations to create the data only take 10 seconds, it seems like a waste to spend 15 minutes uploading it to a database.
Thanks
Mark Jackson
|
|
|
|
|
SQL should be a lot faster. And if network speed is a bottleneck consider running the application on the server.
SQL insert is not the fastest way of doing things. Consider looking into bulk insert methods.
This posting is provided "AS IS" with no warranties, and confers no rights.
Alex Korchemniy
|
|
|
|
|
FWIW, I got around this by creating a huge buffer to hold the data, pasting it to the clipboard, and using a COM object to get Access to paste the data. It is ugly as it appears you cannot import the Access library due to bugs, so I used old-fashioned COM. It was worth the effort as program run time went from over 5 minutes to under 40 seconds.
Mark Jackson
void mrgVaRProdList::uploadList(void)
{
#define APPEND_LINE_SIZE 120
mrgDataSrc * ds;
mrgRecSet rs;
list<mrgVaRPoint *>::iterator iter;
int i;
unsigned long _l, counter;
Date bd, d1, d2;
CString str, buf;
char * chr;
size_t bufLen;
HGLOBAL h;
HWND wh = GetConsoleHWND();
ds = _mParent->getDataObj();
rs.setDataSrc(ds);
bd.setDate(_mParent->getAsOfDate());
str = bd.getDateStr();
i = (int)_uploadList.size();
bufLen = i * APPEND_LINE_SIZE;
h = GlobalAlloc(GHND, bufLen);
try
{
if (!OpenClipboard(wh))
{
throw("OpenClipboard");
}
if (!EmptyClipboard())
{
throw("EmptyClipboard");
}
rs.ExecSQL("Delete * from VaRData");
iter = _uploadList.begin();
counter = 1;
_l = 0;
chr = (char *)GlobalLock(h);
while (iter != _uploadList.end())
{
buf.Format("%u\t%s\t", counter, str);
buf.AppendFormat("%u\t%u\t", (*iter)->idOne, (*iter)->idTwo);
d1.setDate((*iter)->bukOne);
d2.setDate((*iter)->bukTwo);
buf.AppendFormat("%s\t%s\t", d1.getDateStr(), d2.getDateStr());
buf.AppendFormat("%f\t%f\t%f\r\n", (*iter)->rho, (*iter)->sigmaOne, (*iter)->sigmaTwo);
for (i = 0; i < buf.GetLength(); i++)
{
chr[_l] = buf.GetAt(i);
_l++;
}
counter++;
iter++;
}
GlobalUnlock(h);
if (SetClipboardData(CF_TEXT, h) == NULL)
{
throw("SetClipboardData");
}
CloseClipboard();
}
catch(_com_error e)
{
PrintADOError(_T("ADO Error mrgVaRProdList.uploadList() : "), &e);
}
catch(const char *c)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
str.SetString((LPTSTR)lpMsgBuf);
LocalFree(lpMsgBuf);
cout << "Error in mrgVaRProdList.uploadList()-" << c << ":" << str.AllocSysString() << endl;
}
try
{
// our ID's
CLSID clsid;
IUnknown *pUnk;
IDispatch *pDisp;
IDispatch *pDispDoCmd;
DISPID dispid_DoCmd;
DISPID dispid_OpenTable;
DISPID dispid_RunCommand;
//parameter setup
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
OLECHAR FAR* szFunction;
// for getting/passing results
HRESULT hr;
VARIANT varResult;
// arguments for methods
VARIANT varArgs[1];
DISPPARAMS dpArgs;
BSTR bstrTemp;
CLSIDFromProgID(L"Access.Application", &clsid);
// Get an interface to the running instance, if any..
hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);
if (hr < 0)
{
// TODO - we need to start an instance
throw("Error GetActiveObject");
}
// Get IDispatch interface for Automation...
hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDisp);
if (hr < 0)
throw("Error QueryInterface - IID_IDispatch");
// Release the no-longer-needed IUnknown...
pUnk->Release();
szFunction = OLESTR("DoCmd");
hr = pDisp->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_DoCmd);
if (hr < 0)
{
pDisp->Release();
throw("Error GetIDsOfNames for DoCmd");
}
hr = pDisp->Invoke(dispid_DoCmd, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET,
&dispparamsNoArgs, &varResult, NULL, NULL);
if (hr < 0)
{
pDisp->Release();
throw("Error Invoke for DoCmd");
}
pDispDoCmd = varResult.pdispVal;
szFunction = OLESTR("OpenTable");
hr = pDispDoCmd->GetIDsOfNames(IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_OpenTable);
if (hr < 0)
{
pDisp->Release();
pDispDoCmd->Release();
throw("Error GetIDsOfNames for OpenTable");
}
bstrTemp = ::SysAllocString(OLESTR("VaRData"));
varArgs[0].vt = VT_BSTR;
varArgs[0].bstrVal = bstrTemp;
dpArgs.cArgs = 1;
dpArgs.cNamedArgs = 0;
dpArgs.rgvarg = varArgs;
//Invoke the OpenTable Method
hr = pDispDoCmd->Invoke(dispid_OpenTable, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpArgs, NULL, NULL, NULL);
::SysFreeString(bstrTemp);
if (hr < 0)
{
pDisp->Release();
pDispDoCmd->Release();
throw("Error Invoking OpenTable");
}
szFunction = OLESTR("RunCommand");
hr = pDispDoCmd->GetIDsOfNames(IID_NULL, &szFunction, 1,
LOCALE_USER_DEFAULT, &dispid_RunCommand);
if (hr < 0)
{
pDisp->Release();
pDispDoCmd->Release();
throw("Error GetIDsOfNames RunCommand");
}
varArgs[0].vt = VT_I2;
varArgs[0].iVal = 0x26; // acCmdPasteAppend
dpArgs.cArgs = 1;
dpArgs.cNamedArgs = 0;
dpArgs.rgvarg = varArgs;
hr = pDispDoCmd->Invoke(dispid_RunCommand, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD,
&dpArgs, NULL, NULL, NULL);
// release interface pointers
pDispDoCmd->Release();
pDisp->Release();
}
catch(_com_error e)
{
PrintADOError(_T("ADO Error mrgVaRProdList.uploadList() : "), &e);
}
catch(const char *c)
{
cout << "Error in mrgVaRProdList.uploadList()-" << c << endl;
}
return;
}
|
|
|
|
|
i need to use the column names instead of passing magic numbers in my code (i.e. the column position in the select statement).. but it seems that i can't(??) do this??
OracleDataReader reader..;
1st way: NOT READABLE
while (reader.Read())
{
// get the value of 1st column for current row
if (!reader.IsDBNumm(0))
string s = reader.GetString(0);
..
}
2nd way: i can use reader["column_name"], but there is no overload function to test for null value!!! --> STILL NOT READABLE!!!??
while (reader.Read())
{
// get the value of 1st column for current row
if (!reader.IsDBNumm(0))
string s = reader["name"];
..
}
so.. how can i get rid of the magic numbers???
g.
|
|
|
|
|
Hi
Please help me out here with some hierarchies. It’s blowing my mind.
Here’s the table…
CREATE TABLE [dbo].[Tree] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[ParentID] [int] NULL ,
[Lineage] [varchar] (50) NULL ,
[Name] [varchar] (50) NOT NULL
) ON [PRIMARY]
GO
Here’s some data…
SET IDENTITY_INSERT Tree ON
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (1, NULL, '.0001.', 'Root')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (2, 1, '.0001.0002.', 'I')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (3, 1, '.0001.0003.', 'H')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (4, 1, '.0001.0004.', 'G')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (5, 2, '.0001.0002.0005.', 'F')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (6, 2, '.0001.0002.0006.', 'E')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (7, 2, '.0001.0002.0007.', 'D')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (8, 4, '.0001.0004.0008.', 'C')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (9, 4, '.0001.0004.0009.', 'B')
INSERT INTO Tree (ID, ParentID, Lineage, Name) VALUES (10, 3, '.0001.0003.0010.', 'A')
SET IDENTITY_INSERT Tree OFF
You have the above tree data. You can ignore the lineage if you don’t want to work with it.
There problem is as follows…
Please sort the tree nodes according to the hierarchy, BUT the nodes must also be in ALPHABETICAL order.
So “SELECT * FROM Tree ORDER BY Lineage” will look like so…
Root
I
F
E
D
H
A
G
C
B
But I need it to be sorted in that hierarchy but also alphabetically like so
Root
G
B
C
H
A
I
D
E
F
Can someone figure this out for me please?
Regards
Dirk
|
|
|
|
|
Sounds like homework
Try:
SELECT Name FROM Tree ORDER BY (Lineage + Name) DESC
|
|
|
|
|
Just a comment. Think a little more about your 'lineage' field. It seems like you are trying to re-create a character representation for data that already exists through the 'ID' and 'ParentID' fields. I think if you create a view that self joins the table based on the ParentID column you might be farther ahead.
Chris Meech
I am Canadian. [heard in a local bar]
Gently arching his fishing rod back he moves the tip forward in a gentle arch releasing the line.... kersplunk [Doug Goulden]
Nice sig! [Tim Deveaux on Matt Newman's sig with a quote from me]
|
|
|
|
|
Hi,
Hoping someone can help me. I am trying to implement a custom built paging control. I need to retrieve the total number of records as well as only select the number of records I require from the stored procedure and extract these two variables using a sqlDataAdapter.
My sql query is as follows ... would prefer not to use "tomato sauce" but this is the only solution I can think of - however i'm still not getting results .....
And how do I extract these two variables into my sqldataAdapter ...?????
Any advices would be very welcome .. thank you.
My stored procedure ...
alter PROCEDURE [dbo].[prc_tbUser_GetAllPaged1]
--create variable for NumRec
@From int,
@To int
AS
DECLARE @SQL varchar
DECLARE @SQLCount varchar
DECLARE @sSQL varchar
DECLARE @NumRec varchar
set @NumRec = @To - @From
set @SQLCount = 'Declare @TotalRecords int, @NumRec int '
set @SQLCount = @SQLCount + 'SELECT @TotalRecords = count(UserId) from tbUser'
set @SQL = 'SELECT a.Name, a.UserID, a.Login, b.Name as OrganisationName, c.Description as Status
FROM tbUser a
INNER JOIN tbOrganisation b
ON a.OrganisationID = b.OrganisationID
INNER JOIN tbStatus c
ON a.StatusID = c.StatusID'
set @sSQL = @SQLCount + ' SELECT top ' + @NumRec + ' @TotalRecords as NumRecords ' + @SQL
print @sSQL
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
--prc_tbUser_GetAllPaged1 20,40
and this is the sqlDataAdapter ...
connection = new SqlConnection( Configuration.ConnectionString );
command = new SqlCommand( "prc_tbUser_GetAllPaged1", connection );
command.CommandType = CommandType.StoredProcedure;
//From value
command.Parameters.Add( "@From", SqlDbType.Int ).Value = iFrom;
//To value
command.Parameters.Add( "@To", SqlDbType.Int ).Value = iTo;
//need to add another column to read total number of records return
command.Parameters.Add("@TotalRecords", SqlDbType.Int);
// Open the connection
connection.Open();
//create the data adapter
SqlDataAdapter oDA = new SqlDataAdapter(command);
//Gets the parameters set by the user when executing an SQL SELECT statement.
oDA.GetFillParameters();
//execute the reader
oDA.Fill(oDS,iFrom,iTo - iFrom, "tbUser");
return oDS
|
|
|
|
|
Hi everybody
I have created an installer using NSIS,but I am realy having trouble finding the code to attach the database within the installer.I dont know if its maybe my RegKey or what,but the database does not want to attach.If anyone knows anything about NSIS,or maybe a diff RegKey that I can try,or even some coding to help me,please do.
Thanks so much.
Kind Regards
Mattie20
Hello.Thanks for your help
|
|
|
|
|