Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Wednesday, March 28, 2012

Problem returning data

I have a stored procedure (in SQL Server 2005 Express) that returns a string. The problem is when I call it from my web page I get only the first character of the string. This is my SP:

ALTER PROCEDURE

dbo.usp_CalcDeliveryCharge

@.mintDistance

int,

@.mintCustomer_ID

int= 0,

@.mintRate

int= 0OUTPUT,

@.mstrZone

nchar(10) =null OUTPUT

AS

/* SET NOCOUNT ON */SELECT@.mintRate=RATE,

@.mstrZone=ZONE

FROMtblRatesWHERECustomer_ID=@.mintCustomer_IDANDMile_Range_Min <= @.mintDistanceANDMile_Range_Max >= @.mintDistance

And this is my code:

sql_Command.CommandText =

"usp_CalcDeliveryCharge"

sql_Command.CommandType = CommandType.StoredProcedure

sql_Command.Parameters.Clear()

sql_Command.Parameters.AddWithValue(

"@.mintDistance", intApproxMiles)

sql_Command.Parameters.AddWithValue(

"@.mintCustomer_ID", Profile.CompanyID)

sql_Conn.Open()

sql_Reader = sql_Command.ExecuteReader()

While (sql_Reader.Read())Me.lblZone.Text = sql_Reader.Item(0).ToStringEndWhile

sql_Conn.Close()

sql_Reader.Close()

sql_Command.Dispose()

If you are using OUTPUT parameters you need to add the output parameters in the asp.net code also and set their direction as output and retrieve the values through those parameters not through datareader.
checkthis article if it helps.

Monday, March 26, 2012

Problem related to trigger

hi ,
is it possible to use indexof and substring function in trigger.
i am using sql server 2005, please help me how to use string function
in trigger.
thanks
sathya narayanan
narayanan@.gsdindia.com
Hi
SQL Server 2005 Beta/CTP questions to:
http://communities.microsoft.com/new...=sqlserver2005
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"sathya" wrote:

> hi ,
> is it possible to use indexof and substring function in trigger.
> i am using sql server 2005, please help me how to use string function
> in trigger.
> thanks
> sathya narayanan
> narayanan@.gsdindia.com
>
|||hi,
when i am creating update trigger , i cannot read binary or image data
in trigger , i am using sql server 2005 , please help me how to use
image data in after update trigger
my sample code:
alter trigger docsUpdate
on docs
after update
as
declare @.metainfo binary(8000)
declare @.startIndex int
declare @.endIndex int
declare @.metainfoProcc varchar(8000)
declare @.guid varchar(8000)
declare @.order varchar(8000)
Declare metaInfoVal CURSOR for select metainfo from deleted
open metaInfoVal
fetch next from metaInfoVal into @.metainfo
while @.@.fetch_status =0
begin
set @.metainfoProcc = cast(@.metainfo as varchar(8000))
set @.startIndex = charindex('GUID:SW|',@.metainfoProcc,1)+9
set @.endIndex = charindex('*',@.metainfoProcc,@.startIndex)
set @.guid = substring(@.metainfoProcc ,@.startIndex ,
@.endIndex-@.startIndex)
set @.startIndex = charindex('Order:SW|',@.metainfoProcc,1)+9
set @.endIndex = charindex('*',@.metainfoProcc,@.startIndex)
set @.order = substring(@.metainfoProcc ,@.startIndex
,@.endIndex-@.startIndex)
print 'Guid:'+@.guid
print 'order:'+@.order
fetch next from metaInfoVal into @.metainfo
end
close metaInfoVal
deallocate metaInfoVal
it shows error as :
Msg 311, Level 16, State 1, Procedure docsUpdate, Line 11
Cannot use text, ntext, or image columns in the 'inserted' and
'deleted' tables.
sathya narayanan v
narayanan@.gsdindia.com

Problem related to trigger

hi ,
is it possible to use indexof and substring function in trigger.
i am using sql server 2005, please help me how to use string function
in trigger.
thanks
sathya narayanan
narayanan@.gsdindia.comHi
SQL Server 2005 Beta/CTP questions to:
http://communities.microsoft.com/newsgroups/default.asp?icp=sqlserver2005
--
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"sathya" wrote:
> hi ,
> is it possible to use indexof and substring function in trigger.
> i am using sql server 2005, please help me how to use string function
> in trigger.
> thanks
> sathya narayanan
> narayanan@.gsdindia.com
>|||hi,
when i am creating update trigger , i cannot read binary or image data
in trigger , i am using sql server 2005 , please help me how to use
image data in after update trigger
my sample code:
alter trigger docsUpdate
on docs
after update
as
declare @.metainfo binary(8000)
declare @.startIndex int
declare @.endIndex int
declare @.metainfoProcc varchar(8000)
declare @.guid varchar(8000)
declare @.order varchar(8000)
Declare metaInfoVal CURSOR for select metainfo from deleted
open metaInfoVal
fetch next from metaInfoVal into @.metainfo
while @.@.fetch_status =0
begin
set @.metainfoProcc = cast(@.metainfo as varchar(8000))
set @.startIndex = charindex('GUID:SW|',@.metainfoProcc,1)+9
set @.endIndex = charindex('*',@.metainfoProcc,@.startIndex)
set @.guid = substring(@.metainfoProcc ,@.startIndex ,
@.endIndex-@.startIndex)
set @.startIndex = charindex('Order:SW|',@.metainfoProcc,1)+9
set @.endIndex = charindex('*',@.metainfoProcc,@.startIndex)
set @.order = substring(@.metainfoProcc ,@.startIndex
,@.endIndex-@.startIndex)
print 'Guid:'+@.guid
print 'order:'+@.order
fetch next from metaInfoVal into @.metainfo
end
close metaInfoVal
deallocate metaInfoVal
it shows error as :
Msg 311, Level 16, State 1, Procedure docsUpdate, Line 11
Cannot use text, ntext, or image columns in the 'inserted' and
'deleted' tables.
sathya narayanan v
narayanan@.gsdindia.com

Problem related to trigger

hi ,
is it possible to use indexof and substring function in trigger.
i am using sql server 2005, please help me how to use string function
in trigger.
thanks
sathya narayanan
narayanan@.gsdindia.comHi
SQL Server 2005 Beta/CTP questions to:
http://communities.microsoft.com/ne...p=sqlserver2005
--
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"sathya" wrote:

> hi ,
> is it possible to use indexof and substring function in trigger.
> i am using sql server 2005, please help me how to use string function
> in trigger.
> thanks
> sathya narayanan
> narayanan@.gsdindia.com
>|||hi,
when i am creating update trigger , i cannot read binary or image data
in trigger , i am using sql server 2005 , please help me how to use
image data in after update trigger
my sample code:
alter trigger docsUpdate
on docs
after update
as
declare @.metainfo binary(8000)
declare @.startIndex int
declare @.endIndex int
declare @.metainfoProcc varchar(8000)
declare @.guid varchar(8000)
declare @.order varchar(8000)
Declare metaInfoVal CURSOR for select metainfo from deleted
open metaInfoVal
fetch next from metaInfoVal into @.metainfo
while @.@.fetch_status =0
begin
set @.metainfoProcc = cast(@.metainfo as varchar(8000))
set @.startIndex = charindex('GUID:SW|',@.metainfoProcc,1)+9
set @.endIndex = charindex('*',@.metainfoProcc,@.startIndex
)
set @.guid = substring(@.metainfoProcc ,@.startIndex ,
@.endIndex-@.startIndex)
set @.startIndex = charindex('Order:SW|',@.metainfoProcc,1)+
9
set @.endIndex = charindex('*',@.metainfoProcc,@.startIndex
)
set @.order = substring(@.metainfoProcc ,@.startIndex
,@.endIndex-@.startIndex)
print 'Guid:'+@.guid
print 'order:'+@.order
fetch next from metaInfoVal into @.metainfo
end
close metaInfoVal
deallocate metaInfoVal
it shows error as :
Msg 311, Level 16, State 1, Procedure docsUpdate, Line 11
Cannot use text, ntext, or image columns in the 'inserted' and
'deleted' tables.
sathya narayanan v
narayanan@.gsdindia.com

Wednesday, March 21, 2012

Problem Ordering XML using ADO.Net

I am converting some legacy ado code to ado.net. This function uses
'for xml explict' and returns the string representation of the xml. I
add a root node (<sales> ) around that string and load into an xml
document. It would return the following:
<sales>
<transaction>
<terms/>
<terms/>
</transaction>
<transaction>
<terms/>
<terms/>
</transaction>
</sales>
My new code looks like this, it uses the exact same SQL query, The
variable 'RootNode' is passed in and is set to 'sales':
Command = New SqlCommand
Command.CommandText = SQL & ", XMLDATA"
Command.CommandType = CommandType.Text
Command.Connection = Connection
Try
xrReader = Command.ExecuteXmlReader()
Try
Dim ds As DataSet = New DataSet
ds.ReadXml(xrReader, XmlReadMode.Fragment)
ds.DataSetName = RootNode.ToString
Dim DataDoc As XmlDataDocument = New
XmlDataDocument(ds)
strReturn = DataDoc.InnerXml
Catch ex As Exception
strReturn = "</" & RootNode & ">"
End Try
Catch ex As Exception
SaveEvent("CommonADO", "Application", ex.Message,
EventLogEntryType.Error, "EMK3Common.dll")
End Try
This function returns strReturn and looks like the following:
<sales>
<transaction/>
<transaction/>
<terms/>
<terms/>
<terms/>
<terms/>
</sales>
As you can see it does not return the same value. I'm hoping someone
can see what I've done wrong and suggest a fix that will return the
same thing as my old ado dll.
Thanks for your help.Can you post the SQL, i.e. whatever 'SQL' is in the
statement below
Command.CommandText = SQL & ", XMLDATA"
Chances are the ORDER BY clause is incorrect or
missing.|||The SQL is posted below. It returns the data in the correct format
when running it through query analyzer and has worked correctly for the
past two years. The problem seems to be in the conversion from dataset
to xml. Thanks for looking at this.
SELECT 1 AS Tag, NULL AS Parent, lc.TransactionID AS
[transaction!1!TransactionID], lc.ContractID AS
[transaction!1!ContractID],
lc.ContractBeginDate AS
[transaction!1!ContractBeginDate], lc.ContractEndDate AS
[transaction!1!ContractEndDate],
lc.TerminationDate AS
[transaction!1!TerminationDate], lc.LeaseID AS [transaction!1!LeaseID],
lc.NetEstimatedMCFsDay AS
[transaction!1!NetEstimatedMCFsDay], lc.BTUValue AS
[transaction!1!BTUValue],
lc.ServiceType AS [transaction!1!ServiceType],
lc.EstimatedVolumeSell AS [transaction!1!EstimatedVolumeSell],
lc.EstimatedVolumeSell2 AS
[transaction!1!EstimatedVolumeSell2], lc.AutomaticExtensionType AS
[transaction!1!AutomaticExtensionType],
lc.AutomaticExtensionInstr AS
[transaction!1!AutomaticExtensionInstr],
lc.ContractInstr AS
[transaction!1!ContractInstr], lc.EFP AS [transaction!1!EFP],
lc.ConfirmationNumber AS
[transaction!1!ConfirmationNumber], lc.AnalysisDate AS
[transaction!1!AnalysisDate],
lc.ConfirmationDate AS
[transaction!1!ConfirmationDate], lc.BuyerOperationsName AS
[transaction!1!BuyerOperationsName],
lc.BuyerOperationsPhone AS
[transaction!1!BuyerOperationsPhone], lc.BuyerOperationsFax AS
[transaction!1!BuyerOperationsFax],
lc.InvoiceVolumeBasedOn AS
[transaction!1!InvoiceVolumeBasedOn], c.ContractType AS
[transaction!1!ContractType],
l.LeaseType AS [transaction!1!LeaseType],
c.LocalBuyerID AS [transaction!1!LocalBuyerID], c.ProducerID AS
[transaction!1!ProducerID],
c.ContractNo AS [transaction!1!ContractNo],
lc.TransactionID AS [terms!2!TransactionID], NULL AS [terms!2!TermsID],
NULL AS [terms!2!BidValue], NULL
AS [terms!2!BidPercent], NULL AS
[terms!2!PriceBasis], NULL AS [terms!2!NYMEXTriggerRights], NULL AS
[terms!2!NYMEXTriggerParam], NULL
AS [terms!2!NYMEXTriggerDeadline], NULL AS
[terms!2!IndexType1], NULL AS [terms!2!IndexPosting1], NULL AS
[terms!2!TermsBeginDate], NULL
AS [terms!2!TermsEndDate], NULL AS
[terms!2!PercentofProceedsType], NULL AS [terms!2!PercentofProceeds],
NULL
AS [terms!2!NYMEXTriggerPrice], NULL AS
[terms!2!NYMEXTriggerOn], NULL AS [terms!2!NYMEXPriceBasis], NULL
AS [terms!2!AOCalculationType], NULL AS
[terms!2!AOPriceScheduleID1], NULL AS [terms!2!AOPriceScheduleID2],
NULL
AS [terms!2!AOPriceScheduleID3], NULL AS
[terms!2!VolumeCriteria], NULL AS [terms!2!VolumeMin], NULL AS
[terms!2!VolumeMax], NULL
AS [terms!2!VolumeUnit]
FROM gmm_lease l INNER JOIN
gmm_contracttransaction lc ON (l.SellerID =
lc.SellerID AND l.LeaseID = lc.LeaseID) INNER JOIN
gmm_contract c ON (lc.SellerID = c.SellerID AND
lc.ContractID = c.ContractID)
WHERE l.SellerID = 29 AND c.ContractType = 1 AND
(lc.ContractBeginDate <= '5/31/2005' AND (lc.TerminationDate >=
'5/1/2005' OR
lc.TerminationDate IS NULL)) AND l.LeaseID = 2066
GROUP BY lc.TransactionID, lc.ContractID, lc.ContractBeginDate,
lc.ContractEndDate, lc.TerminationDate, lc.LeaseID,
lc.NetEstimatedMCFsDay, lc.BTUValue,
lc.ServiceType, lc.EstimatedVolumeSell,
lc.EstimatedVolumeSell2, lc.AutomaticExtensionType,
lc.AutomaticExtensionInstr, lc.ContractInstr, lc.EFP,
lc.ConfirmationNumber, lc.AnalysisDate,
lc.ConfirmationDate, lc.BuyerOperationsName, lc.BuyerOperationsPhone,
lc.BuyerOperationsFax,
lc.InvoiceVolumeBasedOn, c.ContractType,
l.LeaseType, c.LocalBuyerID, c.ProducerID, c.ContractNo
UNION
SELECT 2, 1, lc.TransactionID, lc.ContractID, lc.ContractBeginDate,
lc.ContractEndDate, lc.TerminationDate, lc.LeaseID,
lc.NetEstimatedMCFsDay, lc.BTUValue,
lc.ServiceType, lc.EstimatedVolumeSell,
lc.EstimatedVolumeSell2, lc.AutomaticExtensionType,
lc.AutomaticExtensionInstr, lc.ContractInstr, lc.EFP,
lc.ConfirmationNumber, lc.AnalysisDate,
lc.ConfirmationDate, lc.BuyerOperationsName, lc.BuyerOperationsPhone,
lc.BuyerOperationsFax,
lc.InvoiceVolumeBasedOn, c.ContractType,
l.LeaseType, c.LocalBuyerID, c.ProducerID, c.ContractNo,
lct.TransactionID, lct.TermsID, lct.BidValue,
lct.BidPercent, lct.PriceBasis,
lct.NYMEXTriggerRights, lct.NYMEXTriggerParam,
lct.NYMEXTriggerDeadline, lct.IndexType1, lct.IndexPosting1,
lct.TermsBeginDate, lct.TermsEndDate,
lct.PercentofProceedsType, lct.PercentofProceeds,
lct.NYMEXTriggerPrice, lct.NYMEXTriggerOn,
lct.NYMEXPriceBasis, lct.AOCalculationType,
lct.AOPriceScheduleID1, lct.AOPriceScheduleID2, lct.AOPriceScheduleID3,
lct.VolumeCriteria,
lct.VolumeMin, lct.VolumeMax, lct.VolumeUnit
FROM gmm_lease l INNER JOIN
gmm_contracttransaction lc ON (l.SellerID =
lc.SellerID AND l.LeaseID = lc.LeaseID) INNER JOIN
gmm_contract c ON (lc.SellerID = c.SellerID AND
lc.ContractID = c.ContractID) INNER JOIN
gmm_contracttransactionterms lct ON (lc.SellerID
= lct.SellerID AND lc.ContractID = lct.ContractID AND lc.TransactionID
= lct.TransactionID)
WHERE l.SellerID = 29 AND c.ContractType = 1 AND
(lc.ContractBeginDate <= '5/31/2005' AND (lc.TerminationDate >=
'5/1/2005' OR
lc.TerminationDate IS NULL)) AND l.LeaseID = 2066
ORDER BY [transaction!1!LeaseID], [transaction!1!TransactionID],
[terms!2!TransactionID], [terms!2!TermsBeginDate]|||The SQL is posted below. It returns the data in the correct format
when running it through query analyzer and has worked correctly for the
past two years. The problem seems to be in the conversion from dataset
to xml. Thanks for looking at this.
SELECT 1 AS Tag, NULL AS Parent, lc.TransactionID AS
[transaction!1!TransactionID], lc.ContractID AS
[transaction!1!ContractID],
lc.ContractBeginDate AS
[transaction!1!ContractBeginDate], lc.ContractEndDate AS
[transaction!1!ContractEndDate],
lc.TerminationDate AS
[transaction!1!TerminationDate], lc.LeaseID AS [transaction!1!LeaseID],
lc.NetEstimatedMCFsDay AS
[transaction!1!NetEstimatedMCFsDay], lc.BTUValue AS
[transaction!1!BTUValue],
lc.ServiceType AS [transaction!1!ServiceType],
lc.EstimatedVolumeSell AS [transaction!1!EstimatedVolumeSell],
lc.EstimatedVolumeSell2 AS
[transaction!1!EstimatedVolumeSell2], lc.AutomaticExtensionType AS
[transaction!1!AutomaticExtensionType],
lc.AutomaticExtensionInstr AS
[transaction!1!AutomaticExtensionInstr],
lc.ContractInstr AS
[transaction!1!ContractInstr], lc.EFP AS [transaction!1!EFP],
lc.ConfirmationNumber AS
[transaction!1!ConfirmationNumber], lc.AnalysisDate AS
[transaction!1!AnalysisDate],
lc.ConfirmationDate AS
[transaction!1!ConfirmationDate], lc.BuyerOperationsName AS
[transaction!1!BuyerOperationsName],
lc.BuyerOperationsPhone AS
[transaction!1!BuyerOperationsPhone], lc.BuyerOperationsFax AS
[transaction!1!BuyerOperationsFax],
lc.InvoiceVolumeBasedOn AS
[transaction!1!InvoiceVolumeBasedOn], c.ContractType AS
[transaction!1!ContractType],
l.LeaseType AS [transaction!1!LeaseType],
c.LocalBuyerID AS [transaction!1!LocalBuyerID], c.ProducerID AS
[transaction!1!ProducerID],
c.ContractNo AS [transaction!1!ContractNo],
lc.TransactionID AS [terms!2!TransactionID], NULL AS [terms!2!TermsID],
NULL AS [terms!2!BidValue], NULL
AS [terms!2!BidPercent], NULL AS
[terms!2!PriceBasis], NULL AS [terms!2!NYMEXTriggerRights], NULL AS
[terms!2!NYMEXTriggerParam], NULL
AS [terms!2!NYMEXTriggerDeadline], NULL AS
[terms!2!IndexType1], NULL AS [terms!2!IndexPosting1], NULL AS
[terms!2!TermsBeginDate], NULL
AS [terms!2!TermsEndDate], NULL AS
[terms!2!PercentofProceedsType], NULL AS [terms!2!PercentofProceeds],
NULL
AS [terms!2!NYMEXTriggerPrice], NULL AS
[terms!2!NYMEXTriggerOn], NULL AS [terms!2!NYMEXPriceBasis], NULL
AS [terms!2!AOCalculationType], NULL AS
[terms!2!AOPriceScheduleID1], NULL AS [terms!2!AOPriceScheduleID2],
NULL
AS [terms!2!AOPriceScheduleID3], NULL AS
[terms!2!VolumeCriteria], NULL AS [terms!2!VolumeMin], NULL AS
[terms!2!VolumeMax], NULL
AS [terms!2!VolumeUnit]
FROM gmm_lease l INNER JOIN
gmm_contracttransaction lc ON (l.SellerID =
lc.SellerID AND l.LeaseID = lc.LeaseID) INNER JOIN
gmm_contract c ON (lc.SellerID = c.SellerID AND
lc.ContractID = c.ContractID)
WHERE l.SellerID = 29 AND c.ContractType = 1 AND
(lc.ContractBeginDate <= '5/31/2005' AND (lc.TerminationDate >=
'5/1/2005' OR
lc.TerminationDate IS NULL)) AND l.LeaseID = 2066
GROUP BY lc.TransactionID, lc.ContractID, lc.ContractBeginDate,
lc.ContractEndDate, lc.TerminationDate, lc.LeaseID,
lc.NetEstimatedMCFsDay, lc.BTUValue,
lc.ServiceType, lc.EstimatedVolumeSell,
lc.EstimatedVolumeSell2, lc.AutomaticExtensionType,
lc.AutomaticExtensionInstr, lc.ContractInstr, lc.EFP,
lc.ConfirmationNumber, lc.AnalysisDate,
lc.ConfirmationDate, lc.BuyerOperationsName, lc.BuyerOperationsPhone,
lc.BuyerOperationsFax,
lc.InvoiceVolumeBasedOn, c.ContractType,
l.LeaseType, c.LocalBuyerID, c.ProducerID, c.ContractNo
UNION
SELECT 2, 1, lc.TransactionID, lc.ContractID, lc.ContractBeginDate,
lc.ContractEndDate, lc.TerminationDate, lc.LeaseID,
lc.NetEstimatedMCFsDay, lc.BTUValue,
lc.ServiceType, lc.EstimatedVolumeSell,
lc.EstimatedVolumeSell2, lc.AutomaticExtensionType,
lc.AutomaticExtensionInstr, lc.ContractInstr, lc.EFP,
lc.ConfirmationNumber, lc.AnalysisDate,
lc.ConfirmationDate, lc.BuyerOperationsName, lc.BuyerOperationsPhone,
lc.BuyerOperationsFax,
lc.InvoiceVolumeBasedOn, c.ContractType,
l.LeaseType, c.LocalBuyerID, c.ProducerID, c.ContractNo,
lct.TransactionID, lct.TermsID, lct.BidValue,
lct.BidPercent, lct.PriceBasis,
lct.NYMEXTriggerRights, lct.NYMEXTriggerParam,
lct.NYMEXTriggerDeadline, lct.IndexType1, lct.IndexPosting1,
lct.TermsBeginDate, lct.TermsEndDate,
lct.PercentofProceedsType, lct.PercentofProceeds,
lct.NYMEXTriggerPrice, lct.NYMEXTriggerOn,
lct.NYMEXPriceBasis, lct.AOCalculationType,
lct.AOPriceScheduleID1, lct.AOPriceScheduleID2, lct.AOPriceScheduleID3,
lct.VolumeCriteria,
lct.VolumeMin, lct.VolumeMax, lct.VolumeUnit
FROM gmm_lease l INNER JOIN
gmm_contracttransaction lc ON (l.SellerID =
lc.SellerID AND l.LeaseID = lc.LeaseID) INNER JOIN
gmm_contract c ON (lc.SellerID = c.SellerID AND
lc.ContractID = c.ContractID) INNER JOIN
gmm_contracttransactionterms lct ON (lc.SellerID
= lct.SellerID AND lc.ContractID = lct.ContractID AND lc.TransactionID
= lct.TransactionID)
WHERE l.SellerID = 29 AND c.ContractType = 1 AND
(lc.ContractBeginDate <= '5/31/2005' AND (lc.TerminationDate >=
'5/1/2005' OR
lc.TerminationDate IS NULL)) AND l.LeaseID = 2066
ORDER BY [transaction!1!LeaseID], [transaction!1!TransactionID],
[terms!2!TransactionID], [terms!2!TermsBeginDate] FOR XML EXPLICIT|||Your SQL looks okay. Suggest you post to an ADO.NET newsgroup.|||I've had another look at this and think that
problem is that the relationship between transaction
and terms isn't coming through from the query. One
solution is to add it yourself by supplying a new
DataRelation object
After
ds.DataSetName = RootNode.ToString
add this (this is C#, but should translate to VB.NET easily)
DataColumn parentCol =
ds.Tables["transaction"].Columns["TransactionID"];
DataColumn childCol = ds.Tables["terms"].Columns["TransactionID"];
DataRelation TransactionTerms = new DataRelation("TransactionTerms",
parentCol, childCol);
ds.Relations.Add(TransactionTerms);
TransactionTerms.Nested = true;

Tuesday, March 20, 2012

problem on running replication on pocket pc

hi i tried to view a replication on a pocket pc app that i created. and i used the following code

private void Sync()
{
public string AppPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
SqlCeReplication repl = new SqlCeReplication();

repl.InternetUrl = @."http://naomi/sqlmobile/sqlcesa30.dll";
repl.Publisher = @."Naomi";
repl.PublisherDatabase = @."SQLMobile";
repl.PublisherSecurityMode = SecurityType.DBAuthentication;
repl.PublisherLogin = @."sa";
repl.PublisherPassword = @."<...>";
repl.Publication = @."SQLMobile";
repl.Subscriber = @."SQLMobile";
repl.SubscriberConnectionString = @."Data Source=""" + AppPath + @."\SqlMobile.sdf"";Max Database Size=128;Default Lock Escalation =100;";
try
{
repl.AddSubscription(AddOption.ExistingDatabase);
repl.Synchronize();
}
catch (SqlCeException e)
{
MessageBox.Show(e.ToString());
}

when i run it i keep on getting the error:
The SQL Mobile Subscription already exists. Publisher, PublisherDatabase, and Publication for this subscription should be different from any existing subscription.

However, i can still view the contents of the datagrid that refers to the database subscription.

1. What should i do in order to stop getting the error above?
2. If i edit the contents of the datagrid in the pocket pc app how will i update the replication in the sql server? thanks

With the line of code "repl.AddSubscription(AddOption.ExistingDatabase)" you are effectively trying to add a new subscription to your local SQL Mobile database every time your synchronize. You only need to perform the AddSubscription the first time you synchronize with the server.

What I typically do is use AddOption.CreateDatabase, which dynamically creates the SQL Mobile database (if it does not already exist) the first time synchronization occurs.

-Darren

Monday, February 20, 2012

problem inserting in database

i have a page writing to a dsatabase. this is the string

<code>

cmd = new sqlcommand("insert into company_locations (company_id, location_type, location_name, contact, address, suite, address2, city, state, zip, phone, extension, fax, comments) Values ('" & provider_id & "', '" & location_type.selectedvalue & "', '" & location_name.text & "', '" & contact.text & "', '" & address.text & "', '" & suite.text & "', '" & address2.text & "', '" & city.text & "', '" & states.selecteditem.value & "', '" & zip.text & "', '" & phone.text & "', '" & extension.text & "', '" & fax.text & "', '" & comments.text & "')", xDb_Conn_Str)

</code>

the problem is that in location_name, I am allowing ' as a valid character. Can anyone help me with this. everytime i execute my statement is truncated because of '.

thanks

Your suffering from a problem that is only slightly less serious than the one that you will face in production: your code is liable to SQL injection attacks, assuming that the input is coming from the user.

Consider what would happen if the entry for, say, contact.text contained:

joe' ); DROP TABLE company_locations; --

Given the right level of privilege, your company_locations table would disappear. Note that this is probably the least of your worries - hackers would start attempting to run command line code on you SQL Server via the built in stored procedure for executing shell code.

You should use parameterised queries to overcome both your problem and to help mitigate against SQL injection attacks. Thus you should be using

... Values( @.ProviderId, @.LocationType, etc. )

for the command text, and then add SqlParameter objects for each parameter

eg

cmd.Parameters.Add( "@.ProviderId", provider_id )

(Note that there are lots of overloads for creating parameters, or you can create the SqlParameter object separately and then add it to the Parameters collection).|||I had understood the problem with sql injectioons. I had already implemented validation string to ensure that certain characters would not be allowed for those exact reason. It was just the ' that I was needing to add. Thanks for the advice you gave me though, it will help. I did not realize that by passing my text as a parameter that I could include the apostrophe. Thanks for the help.|||

msamford wrote:

I had already implemented validation string to ensure thatcertain characters would not be allowed for those exact reason.


This approach (filtering out bad input) is called "blacklisting" and isnot at all recommended. "Whitelisting" (letting in only expectedinput) is much preferred. But parameters are the mostpreferredapproach of all -- you should always use parameters.