|
I am looking for sample code of how to use ADO in Visual C++6.
I want to create a connection to a MS Access Database, open recordsets with SQL-Paramters and create/modify/delete data in different tables.....
thx, Daniel
|
|
|
|
|
I have 8 fields in my table:
century1,year1,month1,day1,century2,year2,month2,day2
20 01 12 01 Null Null Null Null
19 98 01 01 Null Null Null Null
I need to set century2,century2,year2,month2,day2 to the next day
after century1,year1,month1,day1, so my date will look like this:
century1,year1,month1,day1,century2,year2,month2,day2
20 01 12 01 20 01 12 02
19 98 12 31 19 99 01 01
How do I do this?
|
|
|
|
|
Assuming that you are using SQL-Server:
The following will turn your fields into a datetime value:
convert(datetime, day1 + (100 * month1) + (10000 * year1) + (1000000 * century1))
The dateadd functiion will allow you to add one day.
Use convert(char(8), mydate, 112) to convert the date to a character field with the format "YYYYMMDD" (I think 112 is correct - i don't have SQL-server on this machine!).
Use substring to extract each element of the date into string values.
You should be able to stick it all together to solve your problem.
Andy
|
|
|
|
|
Hi,
I want to sent the timeout = 0 to make it wait infinitely. Because I use an IDbCommand variable which actually point to a SqlCommand or OleDbCommand at the runtime, I set IDbCommand.CommandTimeout = 0, but I got the Timeout exception just after a very short time I run the query.
Can anyone tell me why and please help me out.
Thanks in advance.
|
|
|
|
|
I assume that it interprets 0 as zero seconds, i.e. time out immediately.
Try using Int32.MaxValue instead.
|
|
|
|
|
I think so too. But I don't understand how this happened. Because it actually points to the SqlCommand. In SqlCommand, 0 means infinite.
|
|
|
|
|
Hi,
I am using DCOM in my web page and back end is SQL server. My server's(2000)RPC port- 135 is blocked. I need to connect server.How can i establish database connection using ado? (by default port no:1433 for sql server is not sufficient.).
I am using connection string as
"PROVIDER=SQLOLEDB.1;Network Library = dbmssocn;Data Source =datasource,1433;persist Security Info = False;UID=uid;pwd=pwd; Initial Catalog=initial_catalog" .
In web page,i am getting error as "Distributed Transaction Error". But from a separate sample vc++ application, i can establish database connection using this connection string.
Please help me.?
Meenakshi
|
|
|
|
|
I have a DDQ where I am transfering the data from SQL to AS400.
After the DDQ is exists I am updating flag to as success.
If row fails I need to change flag to diference value then if row get transfer suceesufuly.
how do I do this?
|
|
|
|
|
For my test i have created the following stored procedure which is called through a (sqldataconnection, sqldataadater and dataset) created with tthe wizerd. I have also placed a datagrid on the form which thes properties point back to the relivent datasource, datamember and datakeyfield. I have utilized a label to display errors which is telling me that there are now rows to populate the datagrid with.
If I select the dataadapter and run the preview data option (fill in all of the stored procedure variables and click fill data set the table will display the Log_ID value of the record added to the db (value a uniqueid field created by the sql default setting command of (newid()) when a record is added.
***Question why cant i populate the datagrid with the value thacan see when previwing the data through the dataadapter?
--===================================
CREATE PROCEDURE dbo.tsi_spASPautolg
(
@log_date datetime,
@cl_temp nvarchar(255),
@user nvarchar(50),
@domain nvarchar(25),
@pc nvarchar(25),
@ip nvarchar(15),
@mac nvarchar(20)
)
AS
SET NOCOUNT ON;
Insert Into aspAutoLog (Login_datetime, cl_temp, cl_user, cl_domain, cl_pc, cl_ip, cl_mac)
Values (@log_date,@cl_temp,@user,@domain,@pc,@ip,@mac)
SELECT Log_ID From aspAutoLog WHERE login_datetime = @log_date
GO
--===========================================================
On my form I run the following code with a button click:
Try
SqlDataAdapter1.SelectCommand.Parameters("@log_date").Value = Now()
SqlDataAdapter1.SelectCommand.Parameters("@cl_temp").Value = "C:\DOCUME~1\DANJOR~1\LOCALS~1\Temp"
SqlDataAdapter1.SelectCommand.Parameters("@user").Value = "Dan Jordan"
SqlDataAdapter1.SelectCommand.Parameters("@domain").Value = "DEVZONE-DCJXP"
SqlDataAdapter1.SelectCommand.Parameters("@pc").Value = "DEVZONE-DCJXP"
SqlDataAdapter1.SelectCommand.Parameters("@ip").Value = "10.116.105.109"
SqlDataAdapter1.SelectCommand.Parameters("@mac").Value = "00-00-39-5F-7B-3D"
SqlDataAdapter1.Fill(DataSet11, "Log_id")
DataGrid1.DataBind()
DataGrid1.Visible = True
Catch eFillError As System.Exception
Label1.Text = (eFillError.ToString)
Finally
End Try
Thank you for any insite into my confused state...
|
|
|
|
|
I have a program to run a 6-minute query in multi-thread. In each thread it will be executed over and over again. At the beginning the sql server is very busy, but after about 10 minutes, it stops. The cpu becomes free. From the log of my program, I find that the new started thread also kind of stop, it's connecting to the sql server. So I try Query Analyzer and EM, both keep connecting to the sql server until now. It's almost half hour.
Anyone know what's happening here?
Thank you very much.
|
|
|
|
|
Is the machine paging? Pull up the Performance MMC and start looking at more than just processor: disk use, especially paging, is a good place to start. Then get back to me with the details.
Another thing is that depending on how you've got your Query Analyzer etc. set up, you can be inadvertently locking tables by using them through the GUI. I recommend exiting all your client stuff, then starting with just one thread running the query, then two, four, eight, etc. Throw on all the performance monitors you can stand. After a few hours of fiddling around, you will at least have more idea of what's going on on your machine performance-wise.
Also, you should pull up the query plan of your query and analyze it for possibility of deadlock. You can try running it simultaneously through several connections in QA to see if you can cause a deadlock, but I think it's usually better to just try to spot these things with the eye. Look for the possibility of putting two threads at cross purposes, where one thread has resource A and waits on B, while another thread is in the reverse situation. The easiest way to avoid this sort of thing is by making sure you always access things in the same order, and never backtrack if possible. (This is almost always possible to do.)
Sorry if some of this seems like newbie info-- I don't really know your full situation.
Thank you.
Jeff Varszegi
|
|
|
|
|
Below is quoted from a book about ADO.NET, does anyone understand that? Could you please explain a little bit to me or refer me to some link could explain it?
"The .Net framework provides client-side connection pooling for both data providers for connections in a single process, and it also contains provision for working with databases that use server-side connection pooling."
Thanks in advance.
|
|
|
|
|
The functions in ADO.NET are asynchronism or synchronism?
such as, myConnection.Open, myCommand.ExecuteReader.....
|
|
|
|
|
SQL 2000 has a method in the query analyzer to debug a stored procedure. (Use object browser, select the stored proc, then right click and select debug).
This is really nifty, with the exception of passing dates to a datetime parameter. I cannot figure out the format for the date. String mm/dd/yy doesn't work, either with or without single quote.
I am stuck, any help would be greatly appreciated.
"It takes a minimum of redesign to turn a crucifix into a pogo stick"
|
|
|
|
|
yyyy-mm-dd works, IIRC. If all else fails, try converting to a number:
SELECT CAST( CAST( '2003-01-01' AS datetime ) AS int )
|
|
|
|
|
Dave S wrote:
String mm/dd/yy doesn't work, either with or without single quote.
That depends totally on the configuration of the database. There's always the date functions and/or ISO format "yyyy-mm-dd"
--
I am of The Clan of Xymox. I wear a pink kilt!
|
|
|
|
|
Does anybody know of a good tutorial / reference about the expression syntax for DataTable.Select. I am trying to craft a simple query that traverses a child table, the MSDN documenation is shockingly bad
Ryan.
|
|
|
|
|
I am pretty new to C# and the .net framework. I am currently developing a C# application that will be using both ADO.net and ASP.net. I will do my best to describe what my application needs to do eventhough I am not sure of the best way of implementing it. I have a web application that I would like to use as a client that will consume a web service. This web service, which I am trying to create will run SQL commands on an Oracle DB up on our server, read the needed information and generate a crystal report, and make this report file accessible from the client side so the user can choose which report they want to view and any parameters they want to pass. The main stipulation is:
1. My clients do not have to have Oracle Client installed on their machine, this is why I am thinking I need a remote web service that can use the client software up on the server to access the Oracle DB. So that the client software can communicate with the web service and get the needed information to display a crystal report on in formation located from the DB using SQL.
Can anyone give me any ideas on how to structure this project? What should the client do? The service? If you can please be specific as possible as I am somewhat of a newbie. Thanks for all of your help!!
Frank
|
|
|
|
|
Reading from your information.. looks like you want create some Report Application which the data come out from Oracle DB ? is it right ?
Well , you have many choice... but in my opinion, You can create a Web Application , Your web App pull the data from oracle ( we have ODP .NET , check it out on google ) and display it on Crystal Report Viewer for ASP .NET,
of course you can create your own SQL query before retrieve the data.
What is the benefit for your client ?
1. Zero Installation , client only need Web browser don't need oracle client
2. Easily to manage, Just update on server and.. voila all client get the latest software
Is it can help you ? Just email me when you need explaination about the technical details
Cheers,
"Courage choose who will follow, Fate choose who will lead" - Lord Gunner, Septerra Core
|
|
|
|
|
Hi,
I have a program to test the limitation of SQL Server. My idea is to create threads simulating the many clients to connect SQL Server and run a query over and over again, until any one of them fails.
But I am not sure about the connection pooling thing. Should I set the pooling='false'? Because if I use the pooling, then there will have a limitation due to the 'max pool size'. But if I turn off pooling, will it be taking too much time in connecting?
I am not quite get the connection pooling thing even after I read some articles, so could please anyone tell me something about that too?
Thanks in advance.
|
|
|
|
|
yyf wrote:
But if I turn off pooling, will it be taking too much time in connecting?
Connecting to a database is a costly operation. Pooling is much more effective as it "garbage collects" database connections.
First the pool is empty. 5 threads allocate 5 connections. The pool manager sets up 5 connections to the database, and returns handles of them to the client. Now there are 5 connections in the pool, but marked as "not available". The threads return the connections to the pool, leaving the pool with 5 connections, marked as "available". The next thread requesting a connection will get a connection instantly out of the pool. No connecting required.
The pool may also disconnect connections that have been idle for some period of time to reduce resource load.
If there's going to be a lot of connects/disconnects, then I would suggest using a thread pool. Even if you're not using several threads, as it may speed things up considerably.
--
I am of The Clan of Xymox. I wear a pink kilt!
|
|
|
|
|
Hi,
Environment - VB.NET, ASP.NET, SQL Server 2000.
In SQL 2000, I am sending an XML, which carries data for two tables. Let's say, I am inserting half of the fields in TABLE1 and rest in TABLE2.
Specifically, I want to use Transaction Processing for inserting the rows in both tables. If insertion in one table fails, any inserted data should ROLLBACK and come out of procedure with relevant error code.
Please advice or send me any example links. Thanks
Pankaj
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
In the query, assuming use of SQLXML facilities:
BEGIN TRAN
INSERT INTO Table1
SELECT
FROM OPENXML( )
WITH ( )
IF @@ERROR <> 0 THEN
ROLLBACK TRAN
ELSE
INSERT INTO Table2
SELECT
FROM OPENXML( )
WITH ( )
IF @@ERROR <> 0 THEN
ROLLBACK TRAN
ELSE
COMMIT TRAN Basic rule: if you want transactional behaviour, use a TRANSACTION . If your code is implemented as a number of SqlCommand s, it might look more like:
Dim connection As SqlConnection
connection = New SqlConnection( "connectionstring" )
Dim trans As SqlTransaction
Dim cmd1 As SqlCommand
Dim cmd2 As SqlCommand
' Set CommandText for cmd1, cmd2
Try
trans = connection.BeginTransaction()
cmd1.Connection = connection
cmd1.Transaction = trans
cmd2.Connection = connection
cmd2.Transaction = trans
cmd1.ExecuteNonQuery()
cmd2.ExecuteNonQuery()
trans.Commit()
Catch ex As SqlException
trans.Rollback()
End Try
|
|
|
|
|
Thanks for the response.
I am inserting data in two seperate tables by getting data from one XML. So, I want to make sure data either goes in both tables or none. For that I think Transactions are best choice as you explained in Ist example. Right?
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
Hi All!
Can anyone help me with this? It's driving me crazy!
I've reduced a problem application down to the following lines of code.
void TestFunc()
{
::CoInitialize(NULL);
char strTEST[1024];
_ConnectionPtr spConn(__uuidof(Connection));
spConn->Open( "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=;Initial Catalog=TEST_DP;Data Source=(local)", OLESTR(""), OLESTR(""), -1 );
for ( int i = 0; i < 50000; i++ ){
strcpy( strTEST, "SELECT COUNT(*) FROM KGTEST WHERE COL1 = '" );
itoa( i, &strTEST[strlen(strTEST)], 10 );
strcat( strTEST, "'");
_RecordsetPtr spRS(__uuidof(Recordset));
spRS->CursorLocation = adUseClient;
spRS->Open( strTEST, spConn.GetInterfacePtr(), adOpenForwardOnly, adLockBatchOptimistic, -1);
spRS->Close();
spRS = NULL;
}
spConn->Close();
spConn = NULL;
::CoUninitialize();
}
This leaks memory like no tommorrow. It appears to be related to a known Microsoft problem, (Q312575) and the way that memory is cached in MDAC. However this was reported as fixed and does not occur with MDAC 2.7 (According to Microsoft, and this is running with 2.8, and I've re-installed just in case!)
The critical bit seems to be the SQL statement, if it is a constant (For example: SELECT COUNT(*) FROM KGTEST WHERE COL1 = '1' ) - everything is OK, however if the statement is constantly changing then the memory just leaks!
Can anyone shed any light on this?
|
|
|
|
|