Data access in XML from Sql-server200 using asp

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Data access in XML from Sql-server200 using asp

    Dear all,

    i wornder is some one help me.

    i want to access the the data from ms-sql-server2000 to xml file using asp so my
    code is as



    <%@ Language=VBScript %>

    <!--#include file="adovbs.inc" -->
    <%

    Dim adoCmd 'As ADODB.Command
    Dim adoConn ' As ADODB.Connection
    Dim adoStreamQuery ' As ADODB.Stream
    Dim outStrm ' As ADODB.Stream
    Dim txtResults ' String for results
    dim sConn ' String for connection
    dim CmdStream ' as ADODB.Stream

    Const adExecuteStream = 0

    sConn = "Provider=SQLOLEDB;Data Source=TRIDT028;Initial Catalog=Northwind;uid=sa;pwd=trident"
    'sConn = "Provider=SQLXMLOLEDB.3.0;Data Provider=SQLOLEDB;Data Source=TRIDT028;Initial Catalog=Northwind;uid=sa;pwd=trident"

    Set adoConn = CreateObject("ADODB.Connection")
    Set adoStreamQuery = CreateObject("ADODB.Stream")

    adoConn.ConnectionString = sConn
    adoConn.Open

    Set adoCmd = CreateObject("ADODB.Command")
    set adoCmd.ActiveConnection = adoConn

    adoConn.CursorLocation = adUseClient

    Set adoCmd.ActiveConnection = adoConn
    sQuery = "<ROOT xmlns:sql='urn:schemas-microsoft-com:xml-sql'>"
    sQuery = sQuery & "<sql:query>SELECT * FROM PRODUCTS FOR XML AUTO</sql:query>"
    sQuery = sQuery & "</ROOT>"

    adoStreamQuery.Open ' Open the command stream so it may be written to
    adoStreamQuery.WriteText sQuery, adWriteChar ' Set the input command stream's text with the query string
    adoStreamQuery.Position = 0 ' Reset the position in the stream, otherwise it will be at EOS

    Set adoCmd.CommandStream = adoStreamQuery ' Set the command object's command to the input stream set above
    adoCmd.Dialect = "{5D531CB2-E6Ed-11D2-B252-00C04F681B71}" ' Set the dialect for the command stream to be a SQL query.
    Set outStrm = CreateObject("ADODB.Stream") ' Create the output stream
    outStrm.Open
    'adoCmd.Properties("Output Stream") = response ' Set command's output stream to the output stream just opened
    adoCmd.Properties("Output Stream") = outStrm
    adoCmd.Execute , , adExecuteStream ' Execute the command, thus filling up the output stream.
    %>

    but it is giving the error

    ADODB.Command (0x800A0CB3)
    Object or provider is not capable of performing requested operation.

    if i will use the SQLXMLOLEDB as provider and OLEDB as data provider
    then it is giving the error

    SQLXMLOLEDB Provider command object can only execute to a stream.

    so please suggest me the solution.
    thanking u

    Prashant

    Vaibhav Guest

  2. Similar Questions and Discussions

    1. cannot access data source on the web PLEASE help
      Hello everyone?can someone PLEASE help? I have created some Cold Fusion pages and the are working fine via my local server. They connect to a MYSQL...
    2. ASP.NET data access
      I am new to ASP.NET and IIS web applications, but not to SQL databases. I can successfully build Windows apps using Visual Studio that use ADO. ...
    3. Access to AS/400 data
      Does anyone know of any techniques/products which would allow access to AS/400 database files from AIX?
    4. access denied on data access pages
      I have created data access pages that worked well when I tried them on two separate computer simutaneously, but when we went into production we got...
    5. data access
      Hi Is it possible to Join two tables have and have a field from the second table show in a form ? If so could you please point me in the right...
  3. #2

    Default Re: Data access in XML from Sql-server200 using asp

    Vaibhav wrote:
    > but it is giving the error
    >
    > ADODB.Command (0x800A0CB3)
    > Object or provider is not capable of performing requested operation.
    >
    > if i will use the SQLXMLOLEDB as provider and OLEDB as data provider
    > then it is giving the error
    >
    > SQLXMLOLEDB Provider command object can only execute to a stream.
    >
    > so please suggest me the solution.
    > thanking u
    >
    This code works fine on my machine (it uses dynamic sql for demonstrational
    purposes: I have also successfully used stored procedures for this):

    <%
    option explicit
    Response.ContentType="text/xml"
    dim cn, rs,sSQL,cmd,xmldoc
    'Const adExecuteStream = &H00000400
    'Const adCmdText = &H0001
    set cn=server.CreateObject("adodb.connection")

    sSQL="SELECT * FROM Persons ORDER BY LName FOR XML AUTO "
    cn.open "provider=sqloledb;data source=localhost;" & _
    "user id = xxxxxxx; password=xxxxxxx;initial catalog=pubs"
    Set cmd = Server.CreateObject("ADODB.Command")
    Set cmd.ActiveConnection = cn
    cmd.CommandText=sSQL
    cmd.CommandType=adCmdText

    dim str
    Set str =server.createobject("adodb.stream")
    cmd.Properties("xml root").Value = "root"
    str.Open
    cmd.Properties("Output Stream") = str
    cmd.Execute , , 1024

    set xmldoc=server.CreateObject("msxml2.domdocument")
    xmldoc.loadxml str.ReadText
    str.close
    xmldoc.save Response
    cn.close
    set cn=nothing
    %>

    If you still get the error, then you may need to upgrade your MDAC
    installation.

    HTH,
    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows [MVP] Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139