Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Can i insert bulk data to remote sqlserver

Can i insert bulk data to remote sqlserver

Scheduled Pinned Locked Moved Database
questionhelpdatabasexml
11 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S snehasish

    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

    W Offline
    W Offline
    Wendelius
    wrote on last edited by
    #2

    I think you need ADMINISTER BULK OPERATIONS server privilege.

    The need to optimize rises from a bad design.My articles[^]

    S 1 Reply Last reply
    0
    • W Wendelius

      I think you need ADMINISTER BULK OPERATIONS server privilege.

      The need to optimize rises from a bad design.My articles[^]

      S Offline
      S Offline
      snehasish
      wrote on last edited by
      #3

      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?

      W 1 Reply Last reply
      0
      • S snehasish

        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?

        W Offline
        W Offline
        Wendelius
        wrote on last edited by
        #4

        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.

        The need to optimize rises from a bad design.My articles[^]

        S 1 Reply Last reply
        0
        • W Wendelius

          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.

          The need to optimize rises from a bad design.My articles[^]

          S Offline
          S Offline
          snehasish
          wrote on last edited by
          #5

          thanks.i will talk with hosting company according to your advice.

          W 1 Reply Last reply
          0
          • S snehasish

            thanks.i will talk with hosting company according to your advice.

            W Offline
            W Offline
            Wendelius
            wrote on last edited by
            #6

            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.

            The need to optimize rises from a bad design.My articles[^]

            S 1 Reply Last reply
            0
            • W Wendelius

              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.

              The need to optimize rises from a bad design.My articles[^]

              S Offline
              S Offline
              snehasish
              wrote on last edited by
              #7

              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.

              S W 2 Replies Last reply
              0
              • S snehasish

                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.

                S Offline
                S Offline
                snehasish
                wrote on last edited by
                #8

                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 :(

                1 Reply Last reply
                0
                • S snehasish

                  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.

                  W Offline
                  W Offline
                  Wendelius
                  wrote on last edited by
                  #9

                  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[^]).

                  The need to optimize rises from a bad design.My articles[^]

                  S 1 Reply Last reply
                  0
                  • W Wendelius

                    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[^]).

                    The need to optimize rises from a bad design.My articles[^]

                    S Offline
                    S Offline
                    snehasish
                    wrote on last edited by
                    #10

                    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. :) :-D :) :-D 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

                    W 1 Reply Last reply
                    0
                    • S snehasish

                      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. :) :-D :) :-D 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

                      W Offline
                      W Offline
                      Wendelius
                      wrote on last edited by
                      #11

                      Thanks for your kind words :-O

                      The need to optimize rises from a bad design.My articles[^]

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups