Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect SQL Server, Easy Way 1

Status
Not open for further replies.

Rougy

Programmer
Oct 15, 2001
249
US
Hi,

Need to know an easy way to connect to the SQL server via ASP. I code in VB6 all the time, but I can't seem to get over this hurdle.

VB6 code is:

Public cn As New ADODB.Connection
Public rs As ADODB.Recordset

With cn
.ConnectionTimeout = 25
.Provider = "sqloledb"
.Properties("Data Source").Value = "selectpdc"
.Properties("Initial Catalog").Value = "Plant5Milk"
.Properties("User ID").Value = "sa"
.Properties("Password").Value = "select"
.Open
End With

I was hoping ASP VBScript code would be similar.

Thanks a mill,

Rougy

-----
The death of dogma is the birth of reason.
 
Did you have any luck searching for an answer first?

-Tarwn

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
Actually, Tarwin, no...and I have been searching, and continue to do so. Have yet to find anything that quite matches the way ASP looks from my little corner of the world.

I appreciate your concern.

-----
The death of dogma is the birth of reason.
 
I'm trying this, but get: "Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified"

<body>

<%
dim cn
dim cmd

Set cn = Server.CreateObject(&quot;ADODB.Connection&quot;)
cn.Open &quot;DRIVER={SQLOLEDB};SERVER={selectpdc};DATABASE={Plant5Milk};UID={me};PWD={password}&quot;
Set cmd = Server.CreateObject(ADODB.Command)
cmd.activeconnection = cn
cmd.commandtext = &quot;SELECT * FROM ASP&quot;
cmd.execute

Response.Write &quot;Command executed: <BR>&quot;

Set cmd = Nothing
cn.close 'comment this line out to recreate the problem
Set cn = Nothing
%>

</body>

-----
The death of dogma is the birth of reason.
 
Thanks Cathy,

Now it's having problems with this line in the following code:

Set cmd = Server.CreateObject(ADODB.Command)

(thanks for the help)

<%
dim cn
dim rs
dim cmd

Set cn = Server.CreateObject(&quot;ADODB.Connection&quot;)
set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
cn.Open &quot;Provider=sqloledb;&quot; & _
&quot;Network Library=DBMSSOCN;&quot; & _
&quot;Data Source=10.1.1.2,1433;&quot; & _
&quot;Initial Catalog=Database;&quot; & _
&quot;User ID=dbo;&quot; & _
&quot;Password=pwd&quot;
Set cmd = Server.CreateObject(ADODB.Command)
cmd.activeconnection = cn
cmd.commandtext = &quot;SELECT * FROM ASP&quot;
cmd.execute

Response.Write &quot;Command executed: <BR>&quot;

Set cmd = Nothing
cn.close 'comment this line out to recreate the problem
Set cn = Nothing
%>

-----
The death of dogma is the birth of reason.
 
This was the error message:

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'Server'
/sqlconnect.asp, line 23

-----
The death of dogma is the birth of reason.
 
This was the problem, forgot the quotes:

Set cmd = Server.CreateObject(&quot;ADODB.Command&quot;)

I am CONNECTED!

-----
The death of dogma is the birth of reason.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top