|
You cannot do a select from a variable unless the varaible is a table data type. The same applies to @ColumnName.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
This query is totally screwed.
You cannot do the following
ArifShaikh wrote: FROM [@TableName]
There is not such table as @TableName and SQL cannot evaluate the variable in the from clause.
You also cannot do the following
ArifShaikh wrote: WHERE @PrimaryColumn=@PrimaryValue
SQL does not evaluate the variable.
You are going to have to think up a completely different method for logging.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hi,
My problem is that when i want to insert bulk data to my local sqlserver database it execute successfully.the code is:
insert into xmlproperty select * from openrowset(bulk 'C:\celtic\App_Data\PW_XMLfeed_15224.xml',single_clob) as XmlColumn
But when i insert same in remote database it generate error:
Msg 4834, Level 16, State 1, Line 1
You do not have permission to use the bulk load statement.
My question is can i insert bulk data to sqlserver like this way.if not, how can i insert?
wating for reply.
Thanks
snehasish
|
|
|
|
|
I think you need ADMINISTER BULK OPERATIONS server privilege.
|
|
|
|
|
i am using share hosting so sqlserver and xml file is in different places.can i insert this xml data to remote sql server using bulk copy?Does both database and file need to remain in same server?
|
|
|
|
|
snehasish wrote: can i insert this xml data to remote sql server using bulk copy
Yes you can but the SQL Server must have access to the file. Most likely you need to use domain credentials for the account under which the SQL Server is executed and make sure that this account has access to the file via network. Also use UNC-paths to specify the location.
snehasish wrote: Does both database and file need to remain in same server
As I described they don't have to, but it makes things a whole lot easier.
|
|
|
|
|
thanks.i will talk with hosting company according to your advice.
|
|
|
|
|
snehasish wrote: thanks
No problem
If for some reason it becomes a problem to get access from host to the client, you always have other options. For example:
- you could create a stored procedure which takes the xml-data as a parameter. After that you load the data into the xmlproperty-table inside the procedure (not necessarily using file in this case).
- you could use ftp or something else to upload the file to the database server (or near it) and after that you use openrowset from the ftp target location
- if you're using .Net framework at client side, you could use SqlBulkCopy class at the client to load the data to the table etc.
|
|
|
|
|
hi,
Many thanks for giving possible soln. i have tried this one:
........
ds.readxml("http://www.myweb.com/xyz.xml")
Dim xmldoc As New XmlDataDocument(ds)
Dim xd As String = xmldoc.OuterXml()
Dim con As New SqlConnection(constr)
Dim sqlstr As String = "insert into xmlproperty values( convert (xml," & xd & " ))"
Dim com As New SqlCommand(sqlstr, con)
con.Open()
Dim i As Integer = com.ExecuteNonQuery()
con.Close()
.........
first i fill dataset by readxml() method.Then i take xml in variable xd.then i am trying to insert this xml to xmlproperty table.But i get an error:
Incorrect syntax near '<'. The label 'http' has already been declared. Label names must be unique within a query batch or stored procedure. asp.net
how to fix this error.
Thanks.
|
|
|
|
|
hi,
i still getting sql error for this code:
........
ds.readxml("http://www.myweb.com/xyz.xml")
Dim xmldoc As New XmlDataDocument(ds)
Dim xd As String = xmldoc.OuterXml()
Dim con As New SqlConnection(constr)
Dim sqlstr As String = "insert into xmlproperty values( convert (xml," & xd & " ))"
Dim com As New SqlCommand(sqlstr, con)
con.Open()
Dim i As Integer = com.ExecuteNonQuery()
con.Close()
.........
Error:Incorrect syntax near '<'. The label 'http' has already been declared. Label names must be unique within a query batch or stored procedure.
Any help me..
Thanks
Snehasish
|
|
|
|
|
snehasish wrote: Dim sqlstr As String = "insert into xmlproperty values( convert (xml," & xd & " ))"
snehasish wrote: Incorrect syntax near '<'. The label 'http' has already been declared
Don't concatenate the xml to the SQL statement. Instead use parameters (see: SqlParameter[^]).
|
|
|
|
|
Hi;
For some reason i had to go to out of station.According to your suggestion i have solved this.I think you are great.All of your given possible soln is very good.Thank you again.Thanks a lot.
this is my code in vb.net:
Dim ds As New DataSet
ds.ReadXml("http://www.myweb.com/abc.xml")
Dim doc As New XmlDataDocument(ds)
Dim con As New SqlConnection("Server=x.x.x.x;Database=celtic;User ID=xxxx;Password=xxxx;Trusted_Connection=False")
Dim com As New SqlCommand("sp_InsertXmlData", con)
com.CommandType = CommandType.StoredProcedure
com.Parameters.Add("@XMLDOC", SqlDbType.Text).Value = doc.OuterXml
con.Open()
Dim i As Integer = com.ExecuteNonQuery()
con.Close()
This is stored procedure:
Create PROCEDURE [dbo].[sp_InsertXmlData]
@XMLDOC text
AS
BEGIN
insert into xml_properties(xmldoc)
values(@XMLDOC)
END
snehasish
|
|
|
|
|
Thanks for your kind words
|
|
|
|
|
I am using following command:
exec master..xp_cmdshell 'bcp "select * from cab.useraudit" queryout "c:\test.xls" -c -T'
On execution I am getting following error:
Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to
the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the
default settings SQL Server does not allow remote connections
I have configured the server to allow remote connections. What might be wrong?
C isn't that hard: void (*(*f[])())() defines f as an array of unspecified size, of pointers to functions that return pointers to functions that return void
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live." - Martin Golding
|
|
|
|
|
|
Yes I am. I doubted myself and reconfigured everything. Still no help. I am running this on Vista. Is that the problem?
C isn't that hard: void (*(*f[])())() defines f as an array of unspecified size, of pointers to functions that return pointers to functions that return void
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live." - Martin Golding
|
|
|
|
|
I have not tried on Vista. Well did you tried with -U (Userid) and -P (password) switches for bcp command ?
Parwej Ahamad
|
|
|
|
|
It may be firewall issue.
Parwej Ahamad
|
|
|
|
|
If your instance isn't the default instance, you must specify it. Try adding to the end:
-S.\instancename
|
|
|
|
|
I have just the one instance running. Now my belief is getting stronger. Its vista thats playing evil.
C isn't that hard: void (*(*f[])())() defines f as an array of unspecified size, of pointers to functions that return pointers to functions that return void
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live." - Martin Golding
|
|
|
|
|
d@nish wrote: Its vista thats playing evil
I'm not so sure about it. I've got Vista and just tested your problem. Nothing wrong...
Even though you only have one instance it's not necessarily configured as the default. It still may be a named instance. Give it a try. At least if not working it eliminates one possibility.
|
|
|
|
|
Thanks Mika. I have sort of progressed. Now this is what I have done:
exec master..xp_cmdshell 'bcp "select * from cab.useraudit" queryout "c:\test.xls" -S "MACHINE\SQLEXPRESS" -U "uid" -P "pwd"'
Now I am getting this error:
Error = [Microsoft][SQL Native Client][SQL Server]Login failed for user 'Machine\Danish'.
The user is not associated with a trusted SQL Server connection.
How to deal with this?
Please bear. This is the first time I am writing a decent stored procedure.
C isn't that hard: void (*(*f[])())() defines f as an array of unspecified size, of pointers to functions that return pointers to functions that return void
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live." - Martin Golding
|
|
|
|
|
Try also with -T and -P switches.
Parwej Ahamad
|
|
|
|
|
Its not a trusted connection. And with a trusted connection, why would I give a password?
C isn't that hard: void (*(*f[])())() defines f as an array of unspecified size, of pointers to functions that return pointers to functions that return void
"Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live." - Martin Golding
|
|
|
|
|
Instead of using -U and -P switches, use the -T switch (integrated security). In that case yuo connect to the database with the same credentials which actually run the database.
d@nish wrote: Please bear. This is the first time I am writing a decent stored procedure
No problem at all
|
|
|
|