DB connection in asb

J

JIM.H.

Hello
I do not know anything about asb but I just want to import this part of VBscript file to an asp code to help my frined. This part of code is working if I run it as a vbscript on the command line, but we could not get it run in a asb files.

MyODBC = "SQLODBC
MyUsername = "sa
MyPassword = "password

Set objADODBConn = CreateObject("ADODB.Connection"
strConn="DSN=" & MyODBC & ";UID=" & MyUsername & ";PWD=" & MyPassword & ";
objADODBConn.Open(strConn

Any suggestion? Is there anything we miss? Can anyone give us an example to make a ODBC connection in an asb file
Thanks
cT
 
R

Ray at

Are you getting an error of some sort? And dumb question, but are you
saving your files with a .asP extension?

Ray at work

JIM.H. said:
Hello,
I do not know anything about asb but I just want to import this part of
VBscript file to an asp code to help my frined. This part of code is working
if I run it as a vbscript on the command line, but we could not get it run
in a asb files.
MyODBC = "SQLODBC"
MyUsername = "sa"
MyPassword = "password"

Set objADODBConn = CreateObject("ADODB.Connection")
strConn="DSN=" & MyODBC & ";UID=" & MyUsername & ";PWD=" & MyPassword & ";"
objADODBConn.Open(strConn)

Any suggestion? Is there anything we miss? Can anyone give us an example
to make a ODBC connection in an asb file?
 
C

Curt_C [MVP]

Connection Strings http://www.darkfalz.com/1059

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com


JIM.H. said:
Hello,
I do not know anything about asb but I just want to import this part of
VBscript file to an asp code to help my frined. This part of code is working
if I run it as a vbscript on the command line, but we could not get it run
in a asb files.
MyODBC = "SQLODBC"
MyUsername = "sa"
MyPassword = "password"

Set objADODBConn = CreateObject("ADODB.Connection")
strConn="DSN=" & MyODBC & ";UID=" & MyUsername & ";PWD=" & MyPassword & ";"
objADODBConn.Open(strConn)

Any suggestion? Is there anything we miss? Can anyone give us an example
to make a ODBC connection in an asb file?
 
J

JIM.H.

Hello
Yes, there is a asp file and we are trying to embed this script there, we do not know where to start. We put it between <% %> in an asp file, but it does not work and give connection error, even if the script works on the command line
Thanks
Jim
 
R

Ray at

What error?

Ray at work

JIM.H. said:
Hello,
Yes, there is a asp file and we are trying to embed this script there, we
do not know where to start. We put it between <% %> in an asp file, but it
does not work and give connection error, even if the script works on the
command line.
 
B

Bob Barrows

JIM.H. said:
Hello,
Thanks for the reply.
How can I use that test.udl in a asp file?
Thanks,
Jim.

You usually wouldn't. You would open the udl file in a text editor, such as
Notepad, and copy and paste the connection string into your asp page (or an
include file). Like this:

dim cn, sConnect
sConnect="<text copied from udl file>"
set cn=server.createobject("adodb.connection")
cn.Open sConnect


However, if you want to distribute the udl file with your application, you
can use the file itself in the open statement:

cn.open "filename.udl"

HTH,
Bob Barrows
 
T

Turkbear

Hello,
Thanks for the reply.
How can I use that test.udl in a asp file?
Thanks,
Jim.

You don't..You use the text it created ( edit it with notepad) to build your connection string in the asp page.
Here is a for instance
<%
' Create and establish data connection
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30

'Code to connect--------------<This is from the UDL file>
objDC.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Test;Data Source=MySqlServer"
%>:
 
R

Roland Hall

:
: Are you getting an error of some sort? And dumb question, but are you
: saving your files with a .asP extension?

Ray...

I'm surprised you're not familiar with ASB (Active Server Books). It allows
you to run a lot of ASP (Active Server Pages) at one time. (O:=


--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
-Technet Knowledge Base-
http://support.microsoft.com/default.aspx?scid=fh;EN-US;kbhowto&sd=TECH&ln=EN-US&FR=0
-Technet Script Center-
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp
-WSH 5.6 documentation download-
http://www.microsoft.com/downloads/...48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en
-MSDN Library-
http://msdn.microsoft.com/library/default.asp
 
J

JIM.H.

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC SQL Server Driver][Named Pipes]SQL Server does not exist or access denied.
 
R

Ray at

Does this server exist? OECCSQLWEB? Is the server that you're executing
this on able to resolve that name to the IP address of the server? Try
switching it to the IP address of the SQL server. If that works, either
continue using the IP address or solve your name resolution problems on your
web server.

Ray at work
 
B

Bob Barrows

JIM.H. said:
Hello,

This is the code I created through udl and I get the following error.

Code:
Dim objDBConnect

Set objDBConnect = Server.CreateObject("ADODB.Connection")
objDBConnect.Open "Provider=MSDASQL.1;Persist Security
Info=False;User ID=sa;Data Source=OECCSQLWEB"

Error:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver][Named Pipes]SQL Server does not
exist or access denied.
Thanks,
Jim.

You chose the ODBC provider instead of the SQL Server provider when creating
your udl file. And then you selected a DSN form the list. Does this DSN
exist on the web server?

I suggest using OLEDB instead of the obsolet ODBC. Your connection string
should be:

objDBConnect.Open "Provider=SQLOLEDB.1;" & _
"Persist Security Info=False;" & _
"User ID=<some user other than sa>; " & _
"Password=<that user's password>;" & _
"Data Source=<the name of the server itself>"

See www.able-consulting.com/ado_conn.htm for more examples of connection
strings

Don't use the sa account for applications. SA is god in your server! I
don't think you realize the havoc that can be caused by a hacker who manages
to log into your sql server under the sa account. Guard that account as if
your job depended on it - it probably does! Create a new sql login with only
the rights needed to do whatever needs to be done in the database. (You may
need to reconfigure SQL Server to use Mixed Authentication - see Books
Online)

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,250
Latest member
Charlesreero

Latest Threads

Top