Showing posts with label insert. Show all posts
Showing posts with label insert. Show all posts

Friday, March 30, 2012

Problem with SqlDataSource.Insert() using MasterPage

Hi,

because I have had problems with transporting of data from TextBoxes to SQL database in my application using SqlDataSource.Insert(), I tried to analyze it using Microsoft's sample code located here:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insert.aspx

Everything worked well untill I have used masterpage. Since this moment my database table started receive only NULL values - the same problem, which I have in my application. Despite all data values were correct before calling SqlDataSource.Insert() method. Is it some bug or something else (my bugSmile) and how can I resolve it? I'd like to use all advantages of masterpages and datasources together.

Here are non-working codes of spoken sample:

shelter3.aspx

<%@.PageLanguage="VB"MasterPageFile="~/MasterPage3.master"AutoEventWireup="false"CodeFile="shelter3.aspx.vb"Inherits="shelter3"Title="Untitled Page" %>

<asp:ContentID="Content1"ContentPlaceHolderID="Obsah"runat="Server">

<asp:DropDownListID="DropDownList1"runat="server"DataSourceID="SqlDataSource1"

DataTextField="nazev"DataValueField="code"/>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:intranet %>"

SelectCommand="SELECT nazev,code FROM smenky"InsertCommand="INSERT INTO smenky (nazev,code) VALUES (@.nazev,@.code)">

<InsertParameters>

<asp:FormParameterName="nazev"FormField="NazevBox"/>

<asp:FormParameterName="code"FormField="CodeBox"/>

</InsertParameters>

</asp:SqlDataSource>

<p>

<asp:TextBoxID="NazevBox"runat="server"/>

<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="NazevBox"

Display="Static"ErrorMessage="Please enter a company name."/>

<p>

<asp:TextBoxID="CodeBox"runat="server"/>

<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate="CodeBox"

Display="Static"ErrorMessage="Please enter a phone number."/>

<p>

<asp:ButtonID="Button1"runat="server"Text="Insert New Shipper"/>

</asp:Content>

shelter3.aspx.vb

PartialClass shelter3

Inherits System.Web.UI.Page

ProtectedSub InsertShipper(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles Button1.Click

SqlDataSource1.Insert()

EndSub

EndClass

masterpage3.master

<%@.MasterLanguage="VB"CodeFile="MasterPage3.master.vb"Inherits="MasterPage3" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<div>

<asp:contentplaceholderid="Obsah"runat="server">

</asp:contentplaceholder>

</div>

</form>

</body>

</html>

masterpage3.master.vb

PartialClass MasterPage3

Inherits System.Web.UI.MasterPage

EndClass

Thanks for any idea

I reproduced your issue, not sure what's causing the problem. However we can use asp:ControlParameter in this case:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>"

SelectCommand="SELECT id,name FROM test_MasterSqlDataSource" InsertCommand="insert into test_MasterSqlDataSource select @.id,@.name">

<InsertParameters>
<asp:ControlParameter ControlID="NazevBox" PropertyName="Text" Name="id" />

<asp:ControlParameter Name="name" PropertyName="Text" ControlID="CodeBox" />

</InsertParameters>

</asp:SqlDataSource>

I've tested and found the values can be inserted into database properly.

problem with SQLConnection

I am working on a set of webforms that insert user data into a set of db tables.

I set up a test of an approach using northwind and I'm having trouble getting the insert to work. When I open the form, input the name and phone, and submit there is no error, but no record inserted into the Shippers table.

You can see one of my approaches in the ASPX code. I don't like having to do the select in order to do the insert -- so that's commented off.

I'm stuck. Thoughts about what I'm missing appreciated...

Ray

ASPX code.

<%@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default66a.aspx.cs"Inherits="pages_audit_Default66a" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headid="Head1"runat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

CompanyName:

<asp:textboxid="txtCompanyName"runat="server"/><br/>

Phone:

<asp:textboxid="txtPhone"runat="server"/><br/>

<br/>

<asp:buttonid="btnSubmit"runat="server"text="Submit"onclick="btnSubmit_Click"/>

<br/>

<br/>

<br/>

<br/>

<asp:LabelID="awesomelbl"runat="server"Text="Label"></asp:Label><br/>

<br/>

<!--

<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>"

insertcommand="INSERT INTO Shippers(CompanyName, Phone) VALUES (@.CompanyName, @.Phone)" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Shippers]">

<insertparameters>

<asp:controlparameter controlid="txtCompanyName" name="CompanyName" />

<asp:controlparameter controlid="txtPhone" name="Phone" />

</insertparameters>

</asp:sqldatasource>

-->

</form>

</body>

</html>

c Sharp code

using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.Sql;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

publicpartialclasspages_audit_Default66a : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedvoid btnSubmit_Click(object sender,EventArgs e)

{

SqlConnection con =newSqlConnection("Data Source=Chilibowl;Trusted_Connection=yes;DataBase=Northwind");

SqlCommand cmd =newSqlCommand("INSERT INTO [Shippers] ([CompanyName], [Phone]) VALUES (@.CompanyName, @.Phone)");

SqlParameter cnameparam =newSqlParameter("@.CompanyName", txtCompanyName.Text);SqlParameter phnparam =newSqlParameter("@.Phone", txtPhone.Text);

cmd.Parameters.Add(cnameparam);

cmd.Parameters.Add(phnparam);

try

{

con.Open();

if (cmd.ExecuteNonQuery() > 0)awesomelbl.Text ="successful insert";

}

catch

{

//handel

}

finally

{

con.Close();

}

}

}

rkobs:

SqlCommand cmd =newSqlCommand("INSERT INTO [Shippers] ([CompanyName], [Phone]) VALUES (@.CompanyName, @.Phone)");

Try this:

SqlCommand cmd =newSqlCommand("INSERT INTO [Shippers] ([CompanyName], [Phone]) VALUES (@.CompanyName, @.Phone)",con);

|||

Worked. Thanks.

Ray

sql

Wednesday, March 28, 2012

Problem with Sql Server 2000 installation

Hi,
I'm not able to install Microsoft SQL Server 2000 on a Pentium 4 2.40 GHz
with Microsoft Windows 2003 Server.
The problem is:
I insert my SQL Server installation CD in the player. Main window opens up.
I click on "SQL Server 2000 Components", which brings me to the next window.
I click on "Install Database Server" and then window closes... and then
nothing! If I restart the installation, the same thing occurs.
Someone has an idea of what the problem might be?
Thanks!
David
How long do you wait after the click on Install? I seem to recall something
like this but if I waited long enough the next dialog window eventually came
up
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"GeckoNewsgroup" <gecko@.myToto.com> wrote in message
news:BCD3E3D3.1406%gecko@.myToto.com...
> Hi,
> I'm not able to install Microsoft SQL Server 2000 on a Pentium 4 2.40 GHz
> with Microsoft Windows 2003 Server.
> The problem is:
> I insert my SQL Server installation CD in the player. Main window opens
up.
> I click on "SQL Server 2000 Components", which brings me to the next
window.
> I click on "Install Database Server" and then window closes... and then
> nothing! If I restart the installation, the same thing occurs.
> Someone has an idea of what the problem might be?
> Thanks!
> David
>
|||David,
Please dont multipost.I answered this in.setup.
Dinesh
"GeckoNewsgroup" <gecko@.myToto.com> wrote in message
news:BCD3E3D3.1406%gecko@.myToto.com...
> Hi,
> I'm not able to install Microsoft SQL Server 2000 on a Pentium 4 2.40 GHz
> with Microsoft Windows 2003 Server.
> The problem is:
> I insert my SQL Server installation CD in the player. Main window opens
up.
> I click on "SQL Server 2000 Components", which brings me to the next
window.
> I click on "Install Database Server" and then window closes... and then
> nothing! If I restart the installation, the same thing occurs.
> Someone has an idea of what the problem might be?
> Thanks!
> David
>

Problem with Sql Server 2000 installation

Hi,
I'm not able to install Microsoft SQL Server 2000 on a Pentium 4 2.40 GHz
with Microsoft Windows 2003 Server.
The problem is:
I insert my SQL Server installation CD in the player. Main window opens up.
I click on "SQL Server 2000 Components", which brings me to the next window.
I click on "Install Database Server" and then window closes... and then
nothing! If I restart the installation, the same thing occurs.
Someone has an idea of what the problem might be?
Thanks!
DavidHow long do you wait after the click on Install? I seem to recall something
like this but if I waited long enough the next dialog window eventually came
up
--
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"GeckoNewsgroup" <gecko@.myToto.com> wrote in message
news:BCD3E3D3.1406%gecko@.myToto.com...
> Hi,
> I'm not able to install Microsoft SQL Server 2000 on a Pentium 4 2.40 GHz
> with Microsoft Windows 2003 Server.
> The problem is:
> I insert my SQL Server installation CD in the player. Main window opens
up.
> I click on "SQL Server 2000 Components", which brings me to the next
window.
> I click on "Install Database Server" and then window closes... and then
> nothing! If I restart the installation, the same thing occurs.
> Someone has an idea of what the problem might be?
> Thanks!
> David
>|||David,
Please dont multipost.I answered this in.setup.
--
Dinesh
"GeckoNewsgroup" <gecko@.myToto.com> wrote in message
news:BCD3E3D3.1406%gecko@.myToto.com...
> Hi,
> I'm not able to install Microsoft SQL Server 2000 on a Pentium 4 2.40 GHz
> with Microsoft Windows 2003 Server.
> The problem is:
> I insert my SQL Server installation CD in the player. Main window opens
up.
> I click on "SQL Server 2000 Components", which brings me to the next
window.
> I click on "Install Database Server" and then window closes... and then
> nothing! If I restart the installation, the same thing occurs.
> Someone has an idea of what the problem might be?
> Thanks!
> David
>sql

Problem with Sql Server 2000 installation

Hi,
I'm not able to install Microsoft SQL Server 2000 on a Pentium 4 2.40 GHz
with Microsoft Windows 2003 Server.
The problem is:
I insert my SQL Server installation CD in the player. Main window opens up.
I click on "SQL Server 2000 Components", which brings me to the next window.
I click on "Install Database Server" and then window closes... and then
nothing! If I restart the installation, the same thing occurs.
Someone has an idea of what the problem might be?
Thanks!
DavidHow long do you wait after the click on Install? I seem to recall something
like this but if I waited long enough the next dialog window eventually came
up
--
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"GeckoNewsgroup" <gecko@.myToto.com> wrote in message
news:BCD3E3D3.1406%gecko@.myToto.com...
> Hi,
> I'm not able to install Microsoft SQL Server 2000 on a Pentium 4 2.40 GHz
> with Microsoft Windows 2003 Server.
> The problem is:
> I insert my SQL Server installation CD in the player. Main window opens
up.
> I click on "SQL Server 2000 Components", which brings me to the next
window.
> I click on "Install Database Server" and then window closes... and then
> nothing! If I restart the installation, the same thing occurs.
> Someone has an idea of what the problem might be?
> Thanks!
> David
>|||David,
Please dont multipost.I answered this in.setup.
Dinesh
"GeckoNewsgroup" <gecko@.myToto.com> wrote in message
news:BCD3E3D3.1406%gecko@.myToto.com...
> Hi,
> I'm not able to install Microsoft SQL Server 2000 on a Pentium 4 2.40 GHz
> with Microsoft Windows 2003 Server.
> The problem is:
> I insert my SQL Server installation CD in the player. Main window opens
up.
> I click on "SQL Server 2000 Components", which brings me to the next
window.
> I click on "Install Database Server" and then window closes... and then
> nothing! If I restart the installation, the same thing occurs.
> Someone has an idea of what the problem might be?
> Thanks!
> David
>

Monday, March 26, 2012

Problem with SQL Insert

I have this insert command:
string command = "Insert into tbl_books (ID, Title, Series, [Last Name - 1], [First Name - 1], " +
"[Last Name - 2], [First Name - 2], [Last Name- 3], [First Name - 3], [Last Name - 4], " +
"[First Name - 4], [Corporate Author], Edition, Publisher, Copyright, [ISBN Number], " +
"[Call Number - Complete], [Subject Headding - 1], [Subject Heading - 2], [Subjec Heading -3], " +
"Format, Copies, Donor, [In Virgo?], [Number in WorldCat]) " +
"VALUES " +
"(((SELECT MAX(ID) from tbl_books)+1), '" + title + "', '" + series + "', '" + lastName1 + "', '" + firstName1 + "', '" + lastName2 + "', '" +
firstName2 + "', '" + lastName3 + "', '" + firstName3 + "', '" + lastName4 + "', '" + firstName4 + "', '" +
corpAuthor + "', '" + edition + "', '" + publisher + "', '" + copyright + "', '" + isbnNumber + "', '" +
callNumber + "', '" + subject1 + "', '" + subject2 + "', '" + subject3 + "', '" + format + "', '" +
copies + "', '" + donor + "', '" + inVirgo + "', " + worldcat + ")";

SqlDataSource1.InsertCommand = command;
SqlDataSource1.Insert();

But it says that I cannot do subqueries to get the next element of the ID. I dont think that there is automatic numbering on the ID column in the table. What is another way that I could do this? Thank you very much for your help!

you will need to set the ID column as identity column and when you do the insert do not insert any thing in that column, the new ID will generated automatically

|||Thanks, I will try to do that.|||

On another point - i have always been told that if you are building a big query like that then it is more efficient to use a StringBuilder to do so (from the System.Text namespace)

StringBuilder sb = new StringBuilder();

sb.Append("<first line of query>");

etc

then pass sb.ToString(); to get the string back

|||use string builder is good practice for a large web site (a lot of user at the same time). but if this is just a few user, and number of strings you try to concatnate is less then 25, string should be faster then string builder.|||

mm2ha:

I have this insert command:
string command = "Insert into tbl_books (ID, Title, Series, [Last Name - 1], [First Name - 1], " +
"[Last Name - 2], [First Name - 2], [Last Name- 3], [First Name - 3], [Last Name - 4], " +
"[First Name - 4], [Corporate Author], Edition, Publisher, Copyright, [ISBN Number], " +
"[Call Number - Complete], [Subject Headding - 1], [Subject Heading - 2], [Subjec Heading -3], " +
"Format, Copies, Donor, [In Virgo?], [Number in WorldCat]) " +
"VALUES " +
"(((SELECT MAX(ID) from tbl_books)+1), '" + title + "', '" + series + "', '" + lastName1 + "', '" + firstName1 + "', '" + lastName2 + "', '" +
firstName2 + "', '" + lastName3 + "', '" + firstName3 + "', '" + lastName4 + "', '" + firstName4 + "', '" +
corpAuthor + "', '" + edition + "', '" + publisher + "', '" + copyright + "', '" + isbnNumber + "', '" +
callNumber + "', '" + subject1 + "', '" + subject2 + "', '" + subject3 + "', '" + format + "', '" +
copies + "', '" + donor + "', '" + inVirgo + "', " + worldcat + ")";

SqlDataSource1.InsertCommand = command;
SqlDataSource1.Insert();

But it says that I cannot do subqueries to get the next element of the ID. I dont think that there is automatic numbering on the ID column in the table. What is another way that I could do this? Thank you very much for your help!


Please don't build your query in that manner! Never concatenate UI-supplied values to a SQL string that will be executed. I have a standard list of articles that I recommend on this:

Here's the why:

Please, please, please, learn about injection attacks!
And here's the how:
How To: Protect From SQL Injection in ASP.NET
Using Parameterized Query in ASP.NET, Part 1
Using Parameterized Query in ASP.NET, Part 2
Using Parameterized Queries in ASP.Net
Also, please read this Patterns & Practices:
Building Secure ASP.NET Applications: Authentication, Authorization, and Secure Communication
in particular, chapter 12:
Data Access Security

Tuesday, March 20, 2012

Problem with SELECT, GROUP BY and aggregate function

Hi all,

I have a problem with an SQL-query and I don't know what the best solution would be to solve the problem.

/*INSERT INTO WERKS (
WERKS.Z8601,
WERKS.Z8602,
WERKS.Z8603,
WERKS.Z8604,
WERKS.Z8605,
WERKS.Z8606,
WERKS.Z8607,
WERKS.Z8608,
WERKS.Z8609,
WERKS.Z8610,
WERKS.Z8611,
WERKS.Z8621,
WERKS.Z8622,
WERKS.Z8623,
WERKS.Z8624,
WERKS.Z8625,
WERKS.Z8626,
WERKS.Z8627,
WERKS.Z8628,
WERKS.Z8629,
WERKS.Z8630,
WERKS.Z8631,
WERKS.Z8632) */
SELECT
0,
Stati.z4414,
Stati.z4402,
'',
'',
'',
Isnull((select Srtas.z02 from Srtas where Srtas.z00 = Stati.z4400 and Srtas.z01 = Stati.z4414), ''),
Isnull((select Klant.z0102 From Klant where Klant.z0101 = Stati.z4402), ''),
'',
'',
'',
sum (Case when Stati.z4407 = 200609 then Stati.z4409 Else 0 End),
sum (Case when Stati.z4407 = 200609 then Stati.z4410 Else 0 End),
sum (Case when Stati.z4407 = 200509 then Stati.z4409 Else 0 End),
sum (Case when Stati.z4407 = 200509 then Stati.z4410 Else 0 End),
sum (Case when Stati.z4407 Between 200510 and 200609 then Stati.z4409 Else 0 End),
sum (Case when Stati.z4407 Between 200510 and 200609 then Stati.z4410 Else 0 End),
sum (Case when Stati.z4407 Between 200410 and 200509 then Stati.z4409 Else 0 End),
sum (Case when Stati.z4407 Between 200410 and 200509 then Stati.z4410 Else 0 End),
sum (Case when Stati.z4407 = 200609 then Stati.z4411 Else 0 End),
sum (Case when Stati.z4407 = 200509 then Stati.z4411 Else 0 End),
sum (Case when Stati.z4407 Between 200510 and 200609 then Stati.z4411 Else 0 End),
sum (Case when Stati.z4407 Between 200410 and 200509 then Stati.z4411 Else 0 End)
FROM STATI
WHERE
(Stati.z4402 Between '40000' AND 'ZONE6') AND
(Stati.z4414 Between '2005028' AND '2005028') AND
(Stati.z4417 = 'A')
GROUP BY Stati.z4414, Stati.z4402

I get the following error:

Msg 8120, Level 16, State 1, Line 25
Column 'STATI.Z4400' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

I know it has something todo with the select on the table SRTAS, but what's the best way to solve this problem without the chance of getting a wrong result.

The SELECT on SRTAS is to get the "description" of STATI.Z4414 who's stored in the table SRTAS.
I only want to group on the fields that will be inserted in WERKS.Z8602, WERKS.Z8603, WERKS.Z8604, WERKS.Z8605, WERKS.Z8606. So adding STATI.Z4400 to the GROUP BY would give me wrong results?

This query is dynamicly generated from within my program from what the user selected.

Also, if there are better ways to write the query, I would be happy to get some hints and tips, but if possible without stored procedures.

Thanks in advance!

If you really want to use that dynamic query, I would use a Subquery to use the column names to group, otherwise it often the case that you use the overview over the statement.

SELECT col1,col2
FROM
(
Your dynamic query here
) Subquery
Group by col1, col2

HTH, Jens K. Suessmeyer.

http://www.sqlserver205.de|||Assuming the value of STAI.Z4400 is always the same for the group do this:
.
.
.
MAX(Isnull((select Srtas.z02 from Srtas where Srtas.z00 = Stati.z4400 and Srtas.z01 = Stati.z4414), '')),
MAX(Isnull((select Klant.z0102 From Klant where Klant.z0101 = Stati.z4402), '')),
.
.
.

That should fix it.

In this case, it would be easier to JOIN the STAI file intead of doing the subquery. Then just do

CASE WHEN Srtas.z02 IS NULL THEN '' ELSE Srtas.z02 END,
CASE WHEN Klant.z0102 IS NULL THEN '' ELSE Klant.z0102 END,


|||Thank you both for your opinion and help on this problem.

Reading your posts gave me some new ideas so I started changing the query like this:

SELECT

0,

Stati.z4414,

Stati.z4402,

'',

'',

'',

Max(Srtas.z02),

Max(Klant.z0102),

'',

'',

'',

sum (Case when Stati.z4407 = 200609 then Stati.z4409 Else 0 End),

sum (Case when Stati.z4407 = 200609 then Stati.z4410 Else 0 End),

sum (Case when Stati.z4407 = 200509 then Stati.z4409 Else 0 End),

sum (Case when Stati.z4407 = 200509 then Stati.z4410 Else 0 End),

sum (Case when Stati.z4407 Between 200510 and 200609 then Stati.z4409 Else 0 End),

sum (Case when Stati.z4407 Between 200510 and 200609 then Stati.z4410 Else 0 End),

sum (Case when Stati.z4407 Between 200410 and 200509 then Stati.z4409 Else 0 End),

sum (Case when Stati.z4407 Between 200410 and 200509 then Stati.z4410 Else 0 End),

sum (Case when Stati.z4407 = 200609 then Stati.z4411 Else 0 End),

sum (Case when Stati.z4407 = 200509 then Stati.z4411 Else 0 End),

sum (Case when Stati.z4407 Between 200510 and 200609 then Stati.z4411 Else 0 End),

sum (Case when Stati.z4407 Between 200410 and 200509 then Stati.z4411 Else 0 End)

FROM STATI

LEFT JOIN KLANT ON STATI.Z4400 = KLANT.Z0100 AND STATI.Z4402 = KLANT.Z0101

LEFT JOIN SRTAS ON STATI.Z4400 = SRTAS.Z00 AND STATI.Z4414 = SRTAS.Z01

WHERE

(Stati.z4402 Between '40000' AND 'ZONE6') AND

(Stati.z4414 Between '2005028' AND '2005028') AND

(Stati.z4417 = 'A')

GROUP BY Stati.z4414, Stati.z4402

This query seems to work.

I have to admit that there's a huge pile of dust ontop of my MSSQL-knowledge. Been a while since I last used it.

So if any of you have any comments on me doing something wrong, I would be pleased to hear it :-)

Problem with SELECT and INSERT T-sql statement

hello everybody

I want to ask for your help in an issue i am having with SQL Server 2005 Developer Edition . here is the issue:


We have 2 servers called: c10 and cweb. In both, we manually installed SQL server 2005 Dev Edition with no problems.

I created a linked server on c10 to access data on cweb. That is working fine with no problem when executing Select or Insert T-SQL statments like these ones from c10:

select * from cweb.DBNAME.dbo.TableNAME

Or

insert into cweb.DBNAME.dbo.TableNAME (f1, f2, f3)
select f1,f2,f3 from c10.DBNAME.dbo.TableNAME

All works fine up to here. But then there is a new server we setup called c7. This time we created an image of c10 and restore that image on this new server c7. That way, we didnt need to install all software needed in this new server. All software seemed to work ok..but then SQL server 2005 on that new server started failing when doing SELECT t-sql statements.

So Now if i am on c7 and i try to execute this: SELECT * from C7.DNAME.dbo.TableName, it fails

C7 in this case is the local server and it should work. however the error it gives me is that :"linked server not recognize"...it shouldnt need a linked server since it is trying to access the local server. Even with that, i tried to create a linked server to the own local server and now that Select t-sql isntruction worked with no problem..But now here is the othe issue i am having: INSERT t-sql statements are not working. When doing this:


insert into c7.DBNAME.dbo.TableNAME (f1, f2, f3)
select f1,f2,f3 from c7.DBNAME.dbo.TableNAME2

It fails with the following 2 error messages:

"OLE DB provider "SQLNCLI" for linked server "c7" returned message "Multiple-Step OLE DB operation generated errors. Check each OLE DB status, if available. No work was done

The OLE DB provider SQLNCLI for linked server citrix7 could not insert into table c7.DBNAMe.dbo.TableNAme because of column intID. the data value violated the integrity constraints for the column."


I checked that the SELECT part of the INSERT T-sql statement is not retrieving any invalid data for column intID.

I tried restoring the BD on c10 server and tried the same INSERT statement and it worked ok..which mean the data to be inserted is valid.

So i think it is related to some mis-configuration on the linked server or something in SQL server got broken when restoring c10 server image into the new c7 server

So in summary the problem is this:

1. i can not make SELECT T-sql statements using fully qualified names on the local sql server without having a linked server to the local server (which is strange)

2. I can not make INSERT T-sql statements in the local server. This errors happens when doing it

"OLE DB provider "SQLNCLI" for linked server "c7" returned message "Multiple-Step OLE DB operation generated errors. Check each OLE DB status, if available. No work was done

The OLE DB provider SQLNCLI for linked server citrix7 could not insert into table c7.DBNAMe.dbo.TableNAme because of column intID. the data value violated the integrity constraints for the column."

I have been searching thru google and forums but havent found any solutions yet.

Hope you can help me with this..i guess my only option right now is just uninstall and re-install sql server..but maybe there is any other solution to this_?


thanks a lot

Helkyn

This is a Transact-SQL question, not an SSIS question. Moving there...

Monday, March 12, 2012

Problem with rs:SessionId

shotHi group,
When I open a report in my IE a new session (ej:zxzxzxzxzx...) was insert
into table SessionData in my ReportServerTempDB. It's OK. My report hava same
groups and has many drill-drops
But when I open other IE and I give this URL:
http://myServer/reportserver?my_report&rs:SessionId=zxzxzxzx...&rs:Format=PDF,
my server insert a new session and didn't see the same snapshot that the
first time
Any one know why?
Thanks
--
Sorry for my English :)The New IE window is a new session. You cannot share one session with
another.
--
| Thread-Topic: Problem with rs:SessionId
| thread-index: AcTn/YJPkfXUSSGMT06ypAjdL1VwIw==| X-WBNR-Posting-Host: 194.224.254.81
| From: "=?Utf-8?B?SnVhbiBDYXJsb3M=?=" <jcrf@.discussions.microsoft.com>
| Subject: Problem with rs:SessionId
| Date: Wed, 22 Dec 2004 00:09:07 -0800
| Lines: 18
| Message-ID: <EE150D62-13F7-4A0B-A325-AC655FEE5722@.microsoft.com>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.sqlserver.reportingsvcs
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
| Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.reportingsvcs:37925
| X-Tomcat-NG: microsoft.public.sqlserver.reportingsvcs
|
| shotHi group,
|
| When I open a report in my IE a new session (ej:zxzxzxzxzx...) was insert
| into table SessionData in my ReportServerTempDB. It's OK. My report hava
same
| groups and has many drill-drops
|
| But when I open other IE and I give this URL:
|
http://myServer/reportserver?my_report&rs:SessionId=zxzxzxzx...&rs:Format=PD
F,
| my server insert a new session and didn't see the same snapshot that the
| first time
|
|
| Any one know why?
|
| Thanks
|
| --
| Sorry for my English :)
||||ok, thanks, but how it does button "export"?, because when I export to pdf, a
new window it open and the pdf file have my session options.
""Brad Syputa - MS"" wrote:
> The New IE window is a new session. You cannot share one session with
> another.
> --
> | Thread-Topic: Problem with rs:SessionId
> | thread-index: AcTn/YJPkfXUSSGMT06ypAjdL1VwIw==> | X-WBNR-Posting-Host: 194.224.254.81
> | From: "=?Utf-8?B?SnVhbiBDYXJsb3M=?=" <jcrf@.discussions.microsoft.com>
> | Subject: Problem with rs:SessionId
> | Date: Wed, 22 Dec 2004 00:09:07 -0800
> | Lines: 18
> | Message-ID: <EE150D62-13F7-4A0B-A325-AC655FEE5722@.microsoft.com>
> | MIME-Version: 1.0
> | Content-Type: text/plain;
> | charset="Utf-8"
> | Content-Transfer-Encoding: 7bit
> | X-Newsreader: Microsoft CDO for Windows 2000
> | Content-Class: urn:content-classes:message
> | Importance: normal
> | Priority: normal
> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
> | Newsgroups: microsoft.public.sqlserver.reportingsvcs
> | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
> | Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
> | Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.reportingsvcs:37925
> | X-Tomcat-NG: microsoft.public.sqlserver.reportingsvcs
> |
> | shotHi group,
> |
> | When I open a report in my IE a new session (ej:zxzxzxzxzx...) was insert
> | into table SessionData in my ReportServerTempDB. It's OK. My report hava
> same
> | groups and has many drill-drops
> |
> | But when I open other IE and I give this URL:
> |
> http://myServer/reportserver?my_report&rs:SessionId=zxzxzxzx...&rs:Format=PD
> F,
> | my server insert a new session and didn't see the same snapshot that the
> | first time
> |
> |
> | Any one know why?
> |
> | Thanks
> |
> | --
> | Sorry for my English :)
> |
>|||I think he was mistaken. A linked window is part of the same session.
--
Cheers,
'(' Jeff A. Stucker
\
Business Intelligence
www.criadvantage.com
---
"Juan Carlos" <jcrf@.discussions.microsoft.com> wrote in message
news:433D9268-CA7B-46C5-8E26-D8914801CC04@.microsoft.com...
> ok, thanks, but how it does button "export"?, because when I export to
> pdf, a
> new window it open and the pdf file have my session options.
>
> ""Brad Syputa - MS"" wrote:
>> The New IE window is a new session. You cannot share one session with
>> another.
>> --
>> | Thread-Topic: Problem with rs:SessionId
>> | thread-index: AcTn/YJPkfXUSSGMT06ypAjdL1VwIw==>> | X-WBNR-Posting-Host: 194.224.254.81
>> | From: "=?Utf-8?B?SnVhbiBDYXJsb3M=?=" <jcrf@.discussions.microsoft.com>
>> | Subject: Problem with rs:SessionId
>> | Date: Wed, 22 Dec 2004 00:09:07 -0800
>> | Lines: 18
>> | Message-ID: <EE150D62-13F7-4A0B-A325-AC655FEE5722@.microsoft.com>
>> | MIME-Version: 1.0
>> | Content-Type: text/plain;
>> | charset="Utf-8"
>> | Content-Transfer-Encoding: 7bit
>> | X-Newsreader: Microsoft CDO for Windows 2000
>> | Content-Class: urn:content-classes:message
>> | Importance: normal
>> | Priority: normal
>> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
>> | Newsgroups: microsoft.public.sqlserver.reportingsvcs
>> | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.1.29
>> | Path: cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl
>> | Xref: cpmsftngxa10.phx.gbl
>> microsoft.public.sqlserver.reportingsvcs:37925
>> | X-Tomcat-NG: microsoft.public.sqlserver.reportingsvcs
>> |
>> | shotHi group,
>> |
>> | When I open a report in my IE a new session (ej:zxzxzxzxzx...) was
>> insert
>> | into table SessionData in my ReportServerTempDB. It's OK. My report
>> hava
>> same
>> | groups and has many drill-drops
>> |
>> | But when I open other IE and I give this URL:
>> |
>> http://myServer/reportserver?my_report&rs:SessionId=zxzxzxzx...&rs:Format=PD
>> F,
>> | my server insert a new session and didn't see the same snapshot that
>> the
>> | first time
>> |
>> |
>> | Any one know why?
>> |
>> | Thanks
>> |
>> | --
>> | Sorry for my English :)
>> |
>>

Problem with ROWTERMINATOR

I am trying to import data from the text file using BULK INSERT command.

BULK INSERT test.s1_test

FROM 'D:\s1.txt'

WITH

(

CODEPAGE = 1250,

FIELDTERMINATOR = '|',

FIRSTROW = 2,

ROWTERMINATOR = '|\r\n'

)

In the text file in the end of each row is symbol which looks like a square - you can see it here

If I use rowterminator '|\n' of '|\r\n', 0 row(s) affected.

Please, can you help me?

hi,

are you sure it's a CR + LF carachter?

it this is the case, data should show it, but your pic does not..

open it with a hex editor...

regards

Problem with rollback statement

Hi,

I have written a store procedure which inserts data into two tables. What I want do is to rollback transaction if the second insert fails. Below is a code.

Does anyone see my error?

Thanks,

poc1010

Create proc AddProducts

@.dcint=null,
@.pcint=null,
@.imagepathvarchar(50)=null,
@.typevarchar(2)=null,
@.descriptionvarchar(1000)=null,
@.gendervarchar(8)=null,
@.productidint=null,
@.pccodevarchar(2)=null,
@.weightvarchar(80)=null,
@.pricemoney=null,
@.activevarchar(1)=null

as

declare @.errorsave int
set @.errorsave=0
declare @.dg int

Begin transaction

insert productdescription(
designercategory,
productcategory,
imagepath,
type,
[description],
gender)
values(@.dc,
@.pc,
@.imagepath,
@.type,
@.description,
@.gender)

if @.@.error <> 0
set @.errorsave=@.@.error

set @.dg = @.@.identity

begin
insert Products(
productid,
designergroup,
designercategory,
productcategory,
pccode,
weight,
price,
active)
values(@.productid,
@.dg,
@.dc,
@.pc,
@.pccode,
@.weight,
@.price,
@.active)

if @.@.error <> 0
set @.errorsave=@.@.error
end

if @.errorsave <> 0
begin
print 'Insert into Products tables failed'
rollback transaction
return -5--Insert into Products tables failed
end

commit transaction
print 'Success'
return 0 --SuccessYou have begins and ends in useless spots. Whats the acual error message?|||My version of your stored proc (minor changes)

create proc AddProducts
@.dc int = null,
@.pc int = null,
@.imagepath varchar(50) = null,
@.type varchar(2) = null,
@.description varchar(1000) = null,
@.gender varchar(8) = null,
@.productid int = null,
@.pccode varchar(2) = null,
@.weight varchar(80) = null,
@.price money = null,
@.active varchar(1) = null
as
begin

declare @.dg int

begin transaction

insert into productdescription
(designercategory,
productcategory,
imagepath,
type,
[description],
gender)
values(@.dc,
@.pc,
@.imagepath,
@.type,
@.description,
@.gender)
if @.@.error <> 0 or @.@.rowcount <> 1
begin
print 'Insert into Products tables failed'
rollback transaction
return -5 --Insert into Products tables failed
end

set @.dg = @.@.identity

insert into Products
(productid,
designergroup,
designercategory,
productcategory,
pccode,
weight,
price,
active)
values(@.productid,
@.dg,
@.dc,
@.pc,
@.pccode,
@.weight,
@.price,
@.active)
if @.@.error <> 0
begin
print 'Insert into Products tables failed'
rollback transaction
return -5 --Insert into Products tables failed
end

commit transaction
print 'Success'
return 0 --Success

end

|||My version of your stored proc (minor changes)
create proc AddProducts
@.dc int = null,
@.pc int = null,
@.imagepath varchar(50) = null,
@.type varchar(2) = null,
@.description varchar(1000) = null,
@.gender varchar(8) = null,
@.productid int = null,
@.pccode varchar(2) = null,
@.weight varchar(80) = null,
@.price money = null,
@.active varchar(1) = null
as
begin

declare @.dg int

begin transaction

insert into productdescription
(designercategory,
productcategory,
imagepath,
type,
[description],
gender)
values(@.dc,
@.pc,
@.imagepath,
@.type,
@.description,
@.gender)
if @.@.error <> 0 or @.@.rowcount <> 1
begin
print 'Insert into Products tables failed'
rollback transaction
return -5 --Insert into Products tables failed
end

set @.dg = @.@.identity

insert into Products
(productid,
designergroup,
designercategory,
productcategory,
pccode,
weight,
price,
active)
values(@.productid,
@.dg,
@.dc,
@.pc,
@.pccode,
@.weight,
@.price,
@.active)
if @.@.error <> 0
begin
print 'Insert into Products tables failed'
rollback transaction
return -5 --Insert into Products tables failed
end

commit transaction
print 'Success'
return 0 --Success

end

|||None of you guys used ELSE. Your BEGIN/END's are a little whacked out. Honestly, I'm against returning in mid procedure if it's not necessary. You can easily follow through the entire procedure using an ELSE, then returning a specified value.|||Pierre,

Thanks for your example. I saw what I was doing wrong. Works great.

Thank you for your help.

poc1010|||That's just personal taste Lee. No real argument either way. Not in this case.|||You're right. That's why I said that I prefer the other way. Didn't say you were wrong, because it works fine.

Friday, March 9, 2012

Problem with replication

When I try to insert a new record in the subscriber, into a published table, I get a error, saying that it could not execute a stored procedure in the remote server SQLOLEDB. But I when I insert a new record in the publisher, it works correctly, transmitting the changes to the subscriber. What's wrong with it? Both systems are windows 2000 server, with sql server 2000. Thanks.Please give us an idea what type of replication it is?|||- Do you have latest fix installed on the subscriber?
- Does the insertion fire any triggers?|||It is a transactional replication. The error occurs when the subscriber is calling the remote stored procedure in the publisher, which updates the original table.

Problem with Replication

I keep getting an error when I try to set up a merge replication...
Cannot insert duplicate key row in object 'TRDFIL' with unique index
'ITRDFIL0'.
(Source: CMTSQL2 (Data source); Error number: 2601)
I can't seem to figure out how to prevent this from happening, any ideas on
what is not correct?
ThanksHow did you apply your snapshot?
Normally you get this error for one of two reasons.
1) You applied the snapshot manually, either by a restoring a backup, or a
data transfer process (DTS, bcp, etc). Your snapshot is out of sync, and you
are performaning an insert, update operation for which the data already
exists on the Subscriber.
2) Someone or some process has already entered data in the Subscriber, and
the replication process is trying to add the same row.
Use EM, expand your server, expand Replication Monitor, expand the
Publishers Folder, expand your publisher, right click on the publication,
select Validate Subscriptions.
After this process has run, double click on your distribution agent, select
session details to view the results of the data validation process.
"Atley" <atley_1@.homtmail.com> wrote in message
news:eCBH6bVCEHA.2908@.TK2MSFTNGP09.phx.gbl...
> I keep getting an error when I try to set up a merge replication...
> Cannot insert duplicate key row in object 'TRDFIL' with unique index
> 'ITRDFIL0'.
> (Source: CMTSQL2 (Data source); Error number: 2601)
> I can't seem to figure out how to prevent this from happening, any ideas
on
> what is not correct?
> Thanks
>