Connect SQL server issue

Connect SQL server issue

am 14.01.2006 21:30:02 von Souris

I wnated to write a connection to my SQL server, but I got fail.
The folowing is my code.

Can you please tell me where I am wrong?

<%
set conn = Server.CreateObject("ADODB.Connection")
set cmd = Server.CreateObject("ADODB.Command")

sConnString = "Provider=SQLOLEDB.1;User ID=Test1;password=Test1;Initial
Catalog=MyDataBase;Data Source = MyServer"


Conn.Open sConnString
Set cmd.ActiveConnection = Conn
cmd.CommandText = "SELECT * FROM Client"
cmd.CommandType = adCmdText

Set rs = cmd.execute

Do While Not rs.EOF
For iCtr = 0 To rs.fields.Count - 1
response.write rs.fields(iCtr).Name & ": "
response.write rs.fields(iCtr).Value & "
"
Next
rs.MoveNext
Loop
Set rs = Nothing
Set cmd = Nothing
Conn.Close
set conn = nothing

Your information is great appreciated,


I got error message on
"Set cmd.ActiveConnection = Conn"


Error message is following:

Error Type:

ADODB.Command (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another

Re: Connect SQL server issue

am 14.01.2006 22:18:01 von reb01501

Souris wrote:
> I wnated to write a connection to my SQL server, but I got fail.
> The folowing is my code.
>
> Can you please tell me where I am wrong?
>
> <%
> set conn = Server.CreateObject("ADODB.Connection")
> set cmd = Server.CreateObject("ADODB.Command")
>
> sConnString = "Provider=SQLOLEDB.1;User
> ID=Test1;password=Test1;Initial Catalog=MyDataBase;Data Source =
> MyServer"
>
>
> Conn.Open sConnString
> Set cmd.ActiveConnection = Conn
> cmd.CommandText = "SELECT * FROM Client"
> cmd.CommandType = adCmdText
>
> Set rs = cmd.execute
>
> Do While Not rs.EOF
> For iCtr = 0 To rs.fields.Count - 1
> response.write rs.fields(iCtr).Name & ": "
> response.write rs.fields(iCtr).Value & "
"
> Next
> rs.MoveNext
> Loop
> Set rs = Nothing
> Set cmd = Nothing
> Conn.Close
> set conn = nothing
>
> Your information is great appreciated,
>
>
> I got error message on
> "Set cmd.ActiveConnection = Conn"
>
>
> Error message is following:
>
> Error Type:
>
> ADODB.Command (0x800A0BB9)
> Arguments are of the wrong type, are out of acceptable range, or are
> in conflict with one another

Are you sure you have the correct line number? This error message is usually
caused by the failure to define the ADO constants
(http://www.aspfaq.com/show.asp?id=2112) and would have been raised on this
line:
cmd.CommandType = adCmdText

You are overcomplicating this particular task. You do not need an explicit
Command object for what you are doing. Simply:

<%
set conn = Server.CreateObject("ADODB.Connection")
set cmd = Server.CreateObject("ADODB.Command")

sConnString = "Provider=SQLOLEDB.1;User ID=Test1;" & _
"password=Test1;Initial Catalog=MyDataBase;Data Source = MyServer"

Conn.Open sConnString
sql="SELECT * FROM Client"
set rs=conn.execute(sql,,1) '1=adCmdText

You only need an explicit Command object if passing parameters to a stored
procedure or to a string containing parameter markers:
http://groups.google.com/group/microsoft.public.inetserver.a sp.db/msg/72e36562fee7804e

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"

Re: Connect SQL server issue

am 15.01.2006 04:49:02 von Souris

Thanks for the message,
It works.
Are there any place to find the ASP methods and properties information?

Thanks again,





"Bob Barrows [MVP]" wrote:

> Souris wrote:
> > I wnated to write a connection to my SQL server, but I got fail.
> > The folowing is my code.
> >
> > Can you please tell me where I am wrong?
> >
> > <%
> > set conn = Server.CreateObject("ADODB.Connection")
> > set cmd = Server.CreateObject("ADODB.Command")
> >
> > sConnString = "Provider=SQLOLEDB.1;User
> > ID=Test1;password=Test1;Initial Catalog=MyDataBase;Data Source =
> > MyServer"
> >
> >
> > Conn.Open sConnString
> > Set cmd.ActiveConnection = Conn
> > cmd.CommandText = "SELECT * FROM Client"
> > cmd.CommandType = adCmdText
> >
> > Set rs = cmd.execute
> >
> > Do While Not rs.EOF
> > For iCtr = 0 To rs.fields.Count - 1
> > response.write rs.fields(iCtr).Name & ": "
> > response.write rs.fields(iCtr).Value & "
"
> > Next
> > rs.MoveNext
> > Loop
> > Set rs = Nothing
> > Set cmd = Nothing
> > Conn.Close
> > set conn = nothing
> >
> > Your information is great appreciated,
> >
> >
> > I got error message on
> > "Set cmd.ActiveConnection = Conn"
> >
> >
> > Error message is following:
> >
> > Error Type:
> >
> > ADODB.Command (0x800A0BB9)
> > Arguments are of the wrong type, are out of acceptable range, or are
> > in conflict with one another
>
> Are you sure you have the correct line number? This error message is usually
> caused by the failure to define the ADO constants
> (http://www.aspfaq.com/show.asp?id=2112) and would have been raised on this
> line:
> cmd.CommandType = adCmdText
>
> You are overcomplicating this particular task. You do not need an explicit
> Command object for what you are doing. Simply:
>
> <%
> set conn = Server.CreateObject("ADODB.Connection")
> set cmd = Server.CreateObject("ADODB.Command")
>
> sConnString = "Provider=SQLOLEDB.1;User ID=Test1;" & _
> "password=Test1;Initial Catalog=MyDataBase;Data Source = MyServer"
>
> Conn.Open sConnString
> sql="SELECT * FROM Client"
> set rs=conn.execute(sql,,1) '1=adCmdText
>
> You only need an explicit Command object if passing parameters to a stored
> procedure or to a string containing parameter markers:
> http://groups.google.com/group/microsoft.public.inetserver.a sp.db/msg/72e36562fee7804e
>
> 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"
>
>
>

Re: Connect SQL server issue

am 15.01.2006 14:25:04 von reb01501

ASP really is not a language with methods and properties.
http://msdn.microsoft.com/library/default.asp?url=/library/e n-us/iissdk/html/526bf565-7f3e-4c60-a78b-bdac64ebb0e0.asp

It does supply some objects that have methods and properties which you can
read about here:
http://msdn.microsoft.com/library/en-us/iissdk/html/2c40c3cf -90eb-41ca-ae2a-0ef33a651779.asp
specifically in the builtin objects link on that page

I think what you are really asking about in the context of the original post
is the ADO reference which can be found here:
http://msdn.microsoft.com/library/en-us/ado270/htm/dasdkadoo verview.asp

You can download the Windows Scripting Host reference (which includes both
vbscript and jscript) here:
http://tinyurl.com/7rk6

Souris wrote:
> Thanks for the message,
> It works.
> Are there any place to find the ASP methods and properties
> information?
>
> Thanks again,
>
--
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"