ADODB.Connection?

0
August 16, 2011

<b>I am getting an error that says:</b>

"Microsoft OLE DB Provider for ODBC Drivers error '80004005'

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

/asp/hey.asp, line 138 "

<b>Here is the lines</b>

      Set cnnFormToDB = Server.CreateObject("ADODB

.Connectio

n")

            cnnFormToDB.Open strConnString

Here is the entile source:

<%

' Just in case you're not up on my acronyms:

' DB = database, RS=recordset, CONN=connection

' o/w = otherwise

' Include the VBScript ADO constants file

%>

<!-- #INCLUDE FILE="adovbs.inc" -->

<%

' *** Begin DB Setup ***

Dim strConnString

' Sample access OLEDB CONN String.

strConnString = "Provider=Microsoft.Jet.OL

EDB.4.0; Data Source=" & _

      Server.MapPath("db_scratch

.mdb") & ";"

' Override with our site-wide CONN string.

strConnString = Application("SQLConnString

")

' Access likes #, but SQL Server expects ' so you'll need to change

' this based on the DB you're using.

Const DATE_DELIMITER = "'"

' *** End DB Setup ***

Dim cnnFormToDB       ' CONN object

Dim strSQL            ' String in which to build our SQL command

Dim lngRecsAffected   ' # of records affected... just informational

' Vars for the fields read in from the form.  All fields are read

' in as strings so I need to covert them to the appropriate data

' types to be sure they're appropriate for the DB fields.  These

' variables give me some working space to do this easily.

Dim strTextField      ' text field

Dim intIntegerField   ' integer field

Dim datDateTimeField  ' date field

Dim strErrorMsg       ' Holds error message if we catch any problems.

' See if we have any info to process.

' If we don't (ie. the first time through) we just show

' the form.  If we do we proceed with the insert.

If Request.Form("action") <> "Save Form Data" Then

      ' Show the form

      %>

      <FORM ACTION="<%= Request.ServerVariables("S

CRIPT_NAME

") %>" METHOD="post">

      <INPUT TYPE="hidden" NAME="action" VALUE="Save Form Data">

      <TABLE BORDER="0">

      <TR>

            <TD ALIGN="right"><B>Text Field:</B></TD>

            <TD ALIGN="left"><INPUT TYPE="text" NAME="text_field" MAXLENGTH="10"></TD>

      </TR>

      <TR>

            <TD ALIGN="right"><B>Integer Field:</B></TD>

            <TD ALIGN="left"><INPUT TYPE="text" NAME="integer_field"></TD>

      </TR>

      <TR>

            <TD ALIGN="right"><B>Date/Time

Field:</B></TD>

            <TD ALIGN="left"><INPUT TYPE="text" NAME="date_time_field"></T

D>

      </TR>

      <TR>

            <TD> </TD>

            <TD>

                  <INPUT TYPE="reset" VALUE="Clear">

                  <INPUT TYPE="submit" VALUE="Save">

            </TD>

      </TR>

      </TABLE>

      </FORM>

      <%

Else

      ' Do our DB insert!

      ' Retrieve the 3 strings to be entered into the DB

      strTextField     = Request.Form("text_field")

      intIntegerField  = Request.Form("integer_fiel

d")

      datDateTimeField = Request.Form("date_time_fi

eld")

      ' Start error handling... I'm too lazy to check all the criteria

      ' on my own so I use VBScript to do it for me.  I simply do a

      ' conversion the the expected type and if it fails I catch the

      ' error, abort the insert, and display a message.

      On Error Resume Next

      strErrorMsg = ""

      ' String (text) field:

      ' Nothing should really go wrong here.  It's already a string so

      ' I don't bother with a CStr.  I do replace ' with '' for the

      ' validity our SQL statement and also check to make sure it's

      ' not an empty string.  If it is an empty string ("") then I

      ' throw a fake error since I've already got this type of error

      ' handling in place... hey I already admitted I was lazy!

      strTextField = Trim(strTextField)

      If Len(strTextField) = 0 Or Len(strTextField) > 10 Then Err.Raise 1

      strTextField = Replace(strTextField, "'", "''")

      If Err.number <> 0 Then

            strErrorMsg = strErrorMsg & "Your entry for string_field is " & _

                  "inappropriate!<BR>" & vbCrLf

            Err.Clear

      End If

      ' Integer field:

      ' Lots of possible problems here.  First off it could be text and

      ' not a number at all!  Even if it is a number, there are a lot

      ' of restrictions on integers.  It needs to be a whole number and

      ' it's absolute value can't be bigger than around 32,000.  Using

      ' CInt I don't have to worry about it though.

      intIntegerField = CInt(intIntegerField)

      If Err.number <> 0 Then

            strErrorMsg = strErrorMsg & "Your entry for integer_field could " & _

                  "not be converted to an integer!  Remember that integers " & _

                  "need to be from -32,768 to 32,767.<BR>" & vbCrLf

            Err.Clear

      End If            

      ' Date field:

      ' Well it needs to be a valid date.  You can enter it in any format

      ' the computer can understand.  Doing the CDate will not only make

      ' sure it's a date, but will also make them all nice and uniform!

      datDateTimeField = CDate(datDateTimeField)

      If Err.number <> 0 Then

            strErrorMsg = strErrorMsg & "Your entry for date_time_field could " & _

                  "not be converted to an date variable!<BR>" & vbCrLf

            Err.Clear

      End If

      ' I don't know if this is really documented or a hack,

      ' but it turns error trapping back off!

      On Error Goto 0

      ' If we have an error in our error string then we show

      ' the error message o/w we proceed with the insert.

      If strErrorMsg <> "" Then

            ' Show the error message that got us here!

            Response.Write strErrorMsg

      Else

            ' Open connection to the DB

            Set cnnFormToDB = Server.CreateObject("ADODB

.Connectio

n")

            cnnFormToDB.Open strConnString

            ' Build our SQL String

            strSQL = ""

            strSQL = strSQL & "INSERT INTO scratch "

            strSQL = strSQL & "(text_field, integer_field, date_time_field) " & vbCrLf

            strSQL = strSQL & "VALUES ("

            strSQL = strSQL & "'" & strTextField & "'"

            strSQL = strSQL & ", "

            strSQL = strSQL & intIntegerField

            strSQL = strSQL & ", "

            strSQL = strSQL & DATE_DELIMITER & datDateTimeField & DATE_DELIMITER

            strSQL = strSQL & ");"

            ' Execute the SQL command.  I pass it a variable lngRecsAffected

            ' in which to return the number of records affected.  I also tell

            ' it that this is a text command and it won't be returing any

            ' records... this helps it execute the script faster!

            ' And before you ask... I don't know, but YES IT IS OR!!!

            cnnFormToDB.Execute strSQL, lngRecsAffected, adCmdText Or adExecuteNoRecords

            ' Dispose of the CONN object

            cnnFormToDB.Close

            Set cnnFormToDB = Nothing

            ' Display a verification message and we're done!

            %>

            <H2>Thanks for submitting your information to us!</H2>

            <P>

            <B>The resulting SQL statement was:</B>

            <PRE><%= strSQL %></PRE>

            </P>

            <P>

            <B>Number of records affected:</B> <%= lngRecsAffected %>

            </P>

            <%

      End If

End If

%>

Comments See all(0)

Add comment
0
August 16, 2011

I emailed you the source...

0
August 16, 2011

This is just a guess. VBScript is not my strong suite.  In this line there is no DataSource specified. Is it being set somewhere that I do not see?  Also, it says error line 138.  Which line is line 138?

strConnString = "Provider=Microsoft.Jet.OL

EDB.4.0; Data Source=" & _

0
August 16, 2011

Set cnnFormToDB = Server.CreateObject("ADODB

.Connectio

n")

cnnFormToDB.Open strConnString

I think that is line

which give u error

 by the way did u make the system dsn if so then simple replace that line with

cnnFormToDB.Open "DSNname"

then you would not get any error

it is correct way

if you want to acces the database by direct method then you use this code

there is no need to create connection object

strConn = "Provider=Microsoft.Jet.OL

EDB.3.51;D

ata Source=" & server.mappath(".") & "\db.mdb"

0
August 16, 2011

if you need more help then let me know

0
August 16, 2011

No i don't agree with FRehman. He is not using a DSn as per the code. The problem in your code lies in the resetting of your strConnString with Application("SQLConnString

")  which is blank. Thus whatever you are assigning in your previous line of code is overriding with a blank entry, thus generating an error. Either initialize the Application("SQLConnString

")  to the correct value or as  far as i think there isn't any need of doing this via application object. You can very well go for an .inc file.

Regrds

Kamal Ranjan

0
August 16, 2011

I give him both ways

the choice is your

0
August 16, 2011

kamal, how do i do that? i got the code off an example from asp 101, i need to figure out why it works for everyone else but not for me.

0
August 16, 2011

whats problem with my code

0
August 16, 2011

Thanks for your help

0
August 16, 2011

whats going on why you mail him

why you not show us the correct code

is this is secret code,

you not tell me whats the problem with my code

Related Questions

This is the very first question

Hello guys! This is the first post in this site Read More

Views

2k

Votes

4

Answers

2

January 08, 2016

report values not showing up.

I have a crystal report which I pass a DataSet to using VB.NET. The report was working fine, but then I make some changes to the import query and now nothing shows up in the crystal report. Crystal do Read More

Views

1k

Votes

0

Answers

12

September 06, 2005

Event log doesn't overwrite as needed in SP4

Hello All, After upgrading from SP3 to SP4 on several Windows 2000 PRO machines everything looked fine, but from time to time applications can&#39;t write to the event log. When I try to view the appl Read More

Views

1k

Votes

0

Answers

9

May 11, 2003

"Failed to self-register XYZ.dll"

Hi there, I wrote a OLE-automation-server DLL in VB4.0. I use Installshield Express to install it as part of my program on the target computers. Now on some computers I get the message &quot;Failed to Read More

Views

8k

Votes

0

Answers

2

November 08, 1998

Please help understand these notes on image processing

Can someone please help me understand these lecture notes... On the right of the page; What does &quot;normalised by one notion of the area of a pixel&quot; mean? On the first formula for A, Is that a Read More

Views

1k

Votes

0

Answers

3

February 05, 2009

Can someone please explain this paragram on the chain rule in image processing

Please see the screenshot, How is 3133030 got from 10103322? Read More

Views

1k

Votes

0

Answers

1

January 05, 2009

AD on 2003

We have created an AD Domain on Windows 2000 Server with no problems. We just created an AD Domain on Windows 2003 and we&#39;re getting some weird problems. Both of these domains are behind firewalls Read More

Views

1k

Votes

0

Answers

15

May 11, 2003

ADDT ASP Upload Error " Type mismatch: 'tNG_isFileInsideBaseFolder' "

I am trying to create a simple insert record and upload image function on an ASP page built using Adobe Dreamweaver Developer Toolkit. I have done this many times before with no problem, however, i ha Read More

Views

1k

Votes

0

Answers

0

November 02, 2008

MYSQL Select query with custom ORDER BY

Hi, is it possible to customize the order of the returned rows in mysql? Example: I have a Table with a column &quot;name&quot;, now I want to have all entries ordered by name, but I want the entries Read More

Views

1k

Votes

0

Answers

5

July 02, 2010

Folder Redirection in Server 2003

We have a Windows Server 2003 Standard Ed. Is there a way to redirect the users my documents to a folder that has already been created on the server? Read More

Views

1k

Votes

0

Answers

2

July 05, 2007

Partiton magic  version 8.0 having error 1523 while executing batch

I followed the partition magic 8.0 wizard to partition my hard disk while rebooting &#160;I came across this problem &#160;&quot;error 1523 while executing batch&quot; What can I do to solve this prob Read More

Views

1k

Votes

0

Answers

2

May 11, 2003

Please explain this paragraph in image processing (screenshot attached)

Two questions; How is the equation (10.1-15) formed? &quot;are isotropic for rotation increments of 90 degrees and 45 degrees respectively&quot; What does this mean Read More

Views

1k

Votes

0

Answers

7

January 05, 2009

xp_cmdshell with net use

Hi, when I use &#39;net use \192.168.0.1\c$ password /user:username&#39; at the command prompt, it works fine. &#160;But if i try to use it in sql with &quot; exec master..xp_cmdshell &#39;net use \19 Read More

Views

978

Votes

0

Answers

5

April 11, 2003

hp ux11

i have a hp ux11 server. and i edited the /etc/resolv.conf to use my win2003 server dns server. That went fine, however, I would like to go the other way and add an entry on my win2003 dns to resolve Read More

Views

610

Votes

0

Answers

3

October 12, 2009

Using an application over a LAN

I have written an application that needs to be used on a LAN. &#160;The application setup wizard takes care of registering everything on a single PC, but how do you go about writing a setup program th Read More

Views

535

Votes

0

Answers

9

August 07, 1998

Need subnet of 12 IPs.

Please, Can someone help me to create a subnet consisting of 12 IP&#39;s. Thanks.. Read More

Views

538

Votes

0

Answers

5

April 11, 2003

Drill down in a cross-tabl report

Hello, Would some experts to show me if it is possible to do drill-up or drill-down (or both) in a cross-tab report? I would also like to know if it is possible to control what fields to be displayed/ Read More

Views

439

Votes

0

Answers

0

September 06, 2005

Using RDO, Enterprise V Professional

We would like to use RDO on our project made up of 4 developers. Do we need to have a copy of Enterprise for each developer or is it possible to use Professional for those developers not writing the R Read More

Views

523

Votes

0

Answers

6

January 07, 1998

Can't Edit IIS Metabase.xml

We do this on every windows 2003 server and never had an issue. We cannot edit the IIS Metabase.xml We have stopped IIS and made change click save, no problem but it does not take the new information. Read More

Views

510

Votes

0

Answers

0

July 05, 2007

copy directorires - HP UNIX

Let&#39;s say my source file is /A/B/C/D/file1, and mytarget directory is /E/F/G, I want the result should look like this. /E/F/G/A/B/C/D/file1 I am using rsync to copy the files older than x no of da Read More

Views

543

Votes

0

Answers

14

September 12, 2009