|
|
Thanks a lot. Have to read it afterworx though
Matthias
In theory, there is no difference between theory and practice. In practice, however, there is.
(unknown author)
|
|
|
|
|
Please need a solution asap
thanks
I have generated IDs in SQL Server 2000: Data Type = Int, size = 4, seed =1 , seed increment by = 1, precision is 10 digits, scale = 0 digits.
Now i need to format it in 10 digits like if id is 1 then it should be stored and generated in sql server in 10 digits like 0000000001 or 0000000555
----------------------------------
Another problem : in uploading db to sql server 2000 with hosting company. On my machine its working fine with sql server 2000 locally but with the below instructions to upload i cannot connect.
The Server IP address is: 128.121.4.12
You will need to setup an alias in your SQL Server Client Network Utility,
You can name the alias "SQL2K1". Set it to use TCP/IP on port 1433. You can
then set up the new registration in Enterprise Manager. The server name
would be "SQL2K1". The username and password would be the the username and
password you gave when you requested your sql database.
If you have a problem with not being able to connect to the sql server,
you need to verify that you are not behind a firewall, or that your ISP
is not blocking ports 137-139, and 1433. You might also try increasing
the default timeout to 30 seconds. You can find this setting by going to
tools then options, and clicking on the advanced tab.
|
|
|
|
|
Madhusudan wrote:
I have generated IDs in SQL Server 2000: Data Type = Int, size = 4, seed =1 , seed increment by = 1, precision is 10 digits, scale = 0 digits.
Now i need to format it in 10 digits like if id is 1 then it should be stored and generated in sql server in 10 digits like 0000000001 or 0000000555
Not sure I understand the problem. Since you selected int as column type, it will be stored as integer - so if you store value "1", it will be retrieved as "1". Data storage has nothing to do with formatting, you can reformat values using either T-SQL string processing functions - so your program will formatted values, or (which is better, I think) let your program format data when it displays them.
Vagif Abilov
MCP (Visual C++)
Oslo, Norway
Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
|
|
|
|
|
Hi Folks
Re: ADO.NET : SqlDataReader : I need to assign retrieved value to C++ variable
I have found the source of the problem expressed in the thread "ADO.NET : SqlDataReader : I need to assign retrieved value to C++ variable":
http://www.codeproject.com/script/comments/forums.asp?forumid=3785#xx309754xx
but do not yet know why it occurs or how I can fix it.
The problem arises with the /clr compiler setting.
Here is the code to illustrate this:
/////////////////////////////////////////////////////////
#include <stdafx.h>
#include <cstdlib>
#include "try_ADONET.h"
//#using <mscorlib.dll>
//#using <system.dll>
//#using <system.data.dll> // This is required for the ADO.NET Provider
using namespace std;
//using namespace System;
int Main()
{
CString busNumberSQL[2];
CString bus = "Hello";
busNumberSQL[1] = bus;
return 0;
}
////////////////////////////////////////////////////////
Without the /clr setting the array of CString busNumberSQL[2] is correctly contructed as is CString bus and the line
busNumberSQL[1] = bus;
works as expected. This can be seen by putting a breakpoint in at
return 0;
and seeing the variables in a Watch. Copy the expanded Watch details (Name, Value & Type) to an EXCEL sheet.
..................
Next, add the compiler switch /clr and rerun the code.
CString bus is constructed correctly BUT something weird happens in the construction of CString busNumberSQL[2].
Now,
busNumberSQL[1] = bus;
results in the address of bus as an integer being assigned to busNumberSQL[1], and look at the Watch details!!
Copy the expanded Watch details (Name, Value & Type) to an EXCEL sheet
Name: busNumberSQL; Value: {Length=2}; Type: ATL::CStringT<char,strtraitmfc<char,atl::chtraitscrt<char> > >[] ...(Note no dimension at end compared to the "no /clr" case.
Next Watch line: [0] 2083454756 __int32
Next Watch line: [1] 3103464 __int32
My conclusion is that busNumberSQL[2] is not an array of CString.
Of course, I need the /clr in order to use ADO.NET!
It seems as though a CString works, but a CString array for some (unknown) cannot even be defined.
Do you have any light for me? (I have not got into your previous post yet on Marshall)
Best regards
Doug.
(In case you are wondering I am very much a beginner with C++ and .NET)
Doug
|
|
|
|
|
Hmmm...
After reading your question I read this[^] article. It looks like you are going to need to use System::String.
System::String* busNumberSQL[2];
System::String* bus = S"Hello";
busNumberSQL[1] = bus;
Does this help?
Nick Parker
The greatest lesson in life is to know that even fools are right sometimes. - Winston Churchill
|
|
|
|
|
Thanks Nick
using String* exclusively is an option I can adopt.
regards
Doug
Doug
|
|
|
|
|
Doug wrote:
using String* exclusively is an option I can adopt.
You don't have to strictly use String*, you can for example do something like this:
<code>String* SomeString = S"ThisWillWork";</code>
<code>char* szSomeString = (char*)Marshal::StringToGlobalAnsi(SomeString);</code>
<font color="green">
<code>Marshal::FreeHGlobal((int)szSomeString);</code>
HTH
Nick Parker
The greatest lesson in life is to know that even fools are right sometimes. - Winston Churchill
|
|
|
|
|
Yes, another way of skinning the same cat.
Here is what someone wrote :
Quote
I see what you are talking about. Although it is not really a problem but just the way managed code and the CLR interacts with unmanaged code. When you use unmanaged code such as the case with the CString object in your example, and compile with the /clr, the managed executable makes references to the unmanaged objects internally using pointers to its memory location which falls outside the GC managed memory pool. As you have noticed when placing a watch on the unmanaged CString objects which show up as a __int32 type with a value that points to a memory address.
There is nothing wrong with the example you gave in your email. The program still compiles, and the results it produces is as expected. The nice thing with C++.Net is the power of mixing managed and unmanged code in one executable. The power does not come without a price and that is your managed executable with parts unmanaged code, has the same risks as a completely unmanaged executable. The CLR does not offer any protection or resource management to unmanaged objects. So, use the power carefully.
using your example above, if you add to following line to your code you'll see that it still produces the expected results.
Console::Writeline (busNumberSQL[1]);
or even,
printf ("%s",busNumberSQL[1] );
Unquote
http://www.codeproject.com/managedcpp/adonet_mcpp.asp?msg=311206#xx311206xx
PS.
Apologies for the multiple post - the error of my way has been pointed out to me and will not happen again.
Doug
|
|
|
|
|
Doug wrote:
Yes, another way of skinning the same cat.
Hope everything works out for you then.
Nick Parker
The greatest lesson in life is to know that even fools are right sometimes. - Winston Churchill
|
|
|
|
|
Using the SQL object in the System.Data Namespace, not ODBC, how do you normally work out what the user's server name is for assigning to the 'server' property of the ConnectionString?
Andy
|
|
|
|
|
You can't use the System.Data.SqlClient namespace for this. As it requires an active connection to work.
You should let the user configure the name of his SQL Server on initial startup.
Morty
|
|
|
|
|
I have been struggling with several things in Visual Studio .Net
when I upgraded from version 6.0
One thing I have had lots of problems with is the elimination of
support for DaoRecordsets.
I have an Access database that I want to access, and I am struggling
to do it through ODBC. However, one problem I have had that I cannot
seem to get past is trying to get the value of a primary auto number
key out of a newly added record.
With DAO there were a couple of ways to do it:
rs.SetBookmark(rs.GetLastModifiedBookmark());
updates the appropriate field in the recordset.
Or alternatively, using GetFieldValue which forced the field to
be read from the database.
CRecordset does not have a GetLastModifiedBookmark function, and
when I call GetFieldValue it throws an exception.
I've tried various other strategies, but can't seem to find anything
that works. Any help would be much appreciated.
|
|
|
|
|
nde_plume wrote:
However, one problem I have had that I cannot
seem to get past is trying to get the value of a primary auto number
key out of a newly added record.
There are several methods to do this, however here is just one that you can use in Access. Right after the insert you can run this:
<code>SELECT max([Auto_Number_Field])FROM [YourTable];</code>
You might also consider taking the auto number off and finding the maximum value in that column before you do the insert and then insert the maximum value + 1 for your field.
HTH
Nick Parker
The greatest lesson in life is to know that even fools are right sometimes. - Winston Churchill
|
|
|
|
|
|
Daniel Turini wrote:
This is dangerous! Use it only inside a transaction.
Very true, just another option. Transactions are a good thing, however I didn't know the exact scope of the application where this idea may work fine. Thanks for the reminder.
Nick Parker
The greatest lesson in life is to know that even fools are right sometimes. - Winston Churchill
|
|
|
|
|
If you're using Jet 4 / Access 2000, you can use SELECT @@IDENTITY to return the value.
|
|
|
|
|
Stupid question, but I haven't used MSDE before. Here goes, I have MSDE located at:
\\MyPCName\MSDE
or
\\MyPCName\NetSDK
All the examples of ADO.NET use a connection string with:
server=localhost
How do I configure my system to locate the db at localhost?
Cheers
|
|
|
|
|
'\\MyPCName\MSDE' would seem to indicate a network share path, whereas 'localhost' will resolve to the IP address 127.0.0.1
From the little bit of work I've done with SQL Server (as I understand it, MSDE is a mini SQL Server), there are a couple different communication/transport mechanisms it can use. One is TCP/IP, which would use an IP address to connect, and another is using Named Pipes, which would use the netbios-style shares like '\\MyPCName\MSDE'.
I'm guessing that the ADO.NET samples are connecting to the MSDE via TCP/IP, which is why they specify 'localhost' as the server parameter. Poke around in the MSDE settings and see if it mentions anything about being able to communicate to DB clients via TCP/IP...
Sorry I can't be of more help - but it's been years since I fiddled with SQL Server, and I've never even touched MSDE...
--
Russell Morris
"Have you gone mad Frink? Put down that science pole!"
|
|
|
|
|
The connection string for SQL Server/MSDE is typically
Provider=SQLOLEDB;Server=MyPCName;Database=yourdbname;UID=??;PWD=??;
You can omit the Database= bit and it defaults to the default db for the given user.
The MyPCName can be either a machine name or a dotted IP address.
As long as you have the SQL/MSDE client installed (usually via MDAC) it all works quite well.
Steve S
[This signature space available for rent]
|
|
|
|
|
Hi,
Is it possible to use table variables as parameters to a stored procedure?
What i would like to do is:
CREATE PROCEDURE [dbo].[spSetBillingPlan_Custom]
@ContractNumber integer,
@ArgTable TABLE(phasenum integer, perc decimal(5,4))
AS
--yadda yadda yadda
But it doesnt seem to like the table arguement.
If it is not possible, can anyone offer an alternative solution to passing a variable amount of data to a stored proceedure?
Thanks and Regards,
Alex
|
|
|
|
|
This code came from one of the SQL Server sites:
CREATE FUNCTION fn_Split
(
@sText varchar(8000),
@sDelim varchar(20) = ' '
)
RETURNS @retArray TABLE
(
idx smallint Primary Key,
value varchar(8000)
)
AS
BEGIN
DECLARE @idx smallint,
@value varchar(8000),
@bcontinue bit,
@iStrike smallint,
@iDelimlength tinyint
SELECT
@idx = 0,
@bContinue = 1,
@sText = LTrim(RTrim(@sText)),
@iDelimLength = CASE
WHEN @sDelim Is Null THEN 0
WHEN @sDelim = 'Empty' THEN 0
WHEN @sDelim = 'Space' THEN 1
ELSE DataLength(@sDelim)
END,
@sDelim = CASE
WHEN @sDelim Is Null THEN ''
WHEN @sDelim = 'Empty' THEN ''
WHEN @sDelim = 'Space' THEN ' '
ELSE @sDelim
END
IF NOT (@iDelimlength = 0)
BEGIN
WHILE @bcontinue = 1
BEGIN
--If you can find the delimiter in the text, retrieve the first element and
--insert it with its index into the return table.
IF CHARINDEX(@sDelim, @sText)>0
BEGIN
SET @value = LTrim(RTrim(SUBSTRING(@sText,1,CHARINDEX(@sDelim,@sText)-1)))
INSERT INTO @retArray (idx, value)
VALUES (@idx, @value)
--Trim the element and its delimiter from the front of the string.
--Increment the index and loop.
SELECT
@idx = @idx + 1,
@iStrike = DATALENGTH(@value) + @iDelimlength,
@sText = LTrim(RTrim(Right(@sText,DATALENGTH(@sText) - @iStrike)))
END
ELSE
BEGIN
--If you can’t find the delimiter in the text, @sText is the last value in
--@retArray.
SET @value = LTrim(RTrim(@sText))
INSERT INTO @retArray (idx, value)
VALUES (@idx, @value)
--Exit the WHILE loop.
SET @bcontinue = 0
END
END
END
ELSE
BEGIN
WHILE @bcontinue=1
BEGIN
--If the delimiter is an empty string, check for remaining text
--instead of a delimiter. Insert the first character into the
--retArray table. Trim the character from the front of the string.
--Increment the index and loop.
IF DATALENGTH(@sText)>1
BEGIN
SET @value = SUBSTRING(@sText,1,1)
INSERT INTO @retArray (idx, value)
VALUES (@idx, @value)
SELECT
@idx = @idx+1,
@sText = SUBSTRING(@sText,2,DATALENGTH(@sText)-1)
END
ELSE
BEGIN
--One character remains.
--Insert the character, and exit the WHILE loop.
INSERT INTO @retArray (idx, value)
VALUES (@idx, @sText)
SET @bcontinue = 0
END
END
END
RETURN
END
You can pass a list of values separated by commas to your proc, call this function to get a table, and then cast the table values to the type you need. E.g.:
Create Proc dbo.spSetBillingPlan_Custom
(
@ContractNumber int,
@PhaseNum varchar(8000),
@Perc varchar(8000)
)
As
DECLARE @ArgTable TABLE(PhaseNum int, Perc decimal(5,4))
INSERT INTO
@ArgTable (PhaseNum, Perc)
SELECT
CAST(PhaseNum.value As int),
CAST(Perc.value As decimal(5,4))
FROM
dbo.fn_Split(@PhaseNum, ',') As PhaseNum
INNER JOIN
dbo.fn_Split(@Perc, ',') As Perc
On PhaseNum.idx = Perc.idx
--yadda yadda yadda
|
|
|
|
|
As you have correctly pointed out. SQL Server 2000 doesn't allow table variables as input parameters in stored procedures.
What you could use instead is the "politically correct" xml document. Pass an xml document (array... ) to the SQL Server, and use the OPENXML statement to process it.
Morty
|
|
|
|
|
.. anyone know what it is?
I thought it was nvarchar but I cant get it to go higher than 4000.
|
|
|
|
|
Ray Cassick wrote:
.. anyone know what it is?
I thought it was nvarchar but I cant get it to go higher than 4000.
Text.
But be warned the Text data type can be an utter pain in the neck. My recommendation is to put it as the last field in a table and then sacrifice a virgin to the SQL god on the slopes of Mount Kiloquery.
Also it is a pain to edit a Text field within QA or Enterprise Manager. Generally Text fields suck IMO.
|
|
|
|
|