conditional connection string

L

ll

Hi,
I'm having a little trouble with the following code. For some reason,
when x=true, both parts of the If Then...Else statement are followed,
and the data winds up being in the Data Source in the Else section,
even though x tests positive as true (the response.write statement).
Could this be a problem with the variable or perhaps grouping?

Thanks,
Louis

========================
'begin conditional connection section
x=true
If x=true Then
Function GetConnection()
dim Conn: Set Conn = CreateObject("ADODB.Connection")
Conn.open "Provider=SQLOLEDB.1;" &_
"Persist Security Info=False;" &_
"User ID=CopRandW;Password=Pharm_1110;" &_
"Initial Catalog=cop_pcms;" &_
"Data Source=COP-CPB-DAT"
set GetConnection = Conn
end function
response.write("hi - x is true!")
Else
Function GetConnection()
dim Conn: Set Conn = CreateObject("ADODB.Connection")
Conn.open "Provider=SQLOLEDB.1;" &_
"Persist Security Info=False;" &_
"User ID=CopRandW;Password=Pharm_1110;" &_
"Initial Catalog=cop;" &_
"Data Source=COP-CPB-DAT"
set GetConnection = Conn
end function
response.write("hi - x is false!")
End If

'end conditional connection section
 
B

Bob Barrows [MVP]

ll said:
Hi,
I'm having a little trouble with the following code. For some reason,
when x=true, both parts of the If Then...Else statement are followed,
and the data winds up being in the Data Source in the Else section,
even though x tests positive as true (the response.write statement).
Could this be a problem with the variable or perhaps grouping?

Thanks,
Louis

========================
'begin conditional connection section
x=true
If x=true Then
Function GetConnection()

Your subject is misleading: you should have said "conditional function
declarations" which is not possible in vbscript
(http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx). Both
functions get declared and probably cause an "already declared" error. You
need to create a single function with arguments whose values get set when
you call it in the if construct.
 
L

ll

Your subject is misleading: you should have said "conditional function
declarations" which is not possible in vbscript
(http://blogs.msdn.com/ericlippert/archive/2004/06/18/159378.aspx). Both
functions get declared and probably cause an "already declared" error. You
need to create a single function with arguments whose values get set when
you call it in the if construct.

--
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"



Thanks for the leads! Yes, now that the arguments are within one
function, it works much better.
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top