Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dynamic connection string

0 views
Skip to first unread message

coolnamewithheld

unread,
Jul 27, 2009, 5:51:52 PM7/27/09
to

How do I create a dynamic connection string with the name of the
data source being passed as a variable.

The way I want this to work is the server name is passed from a
classic asp page as a input from a form:

srvName=trim(Request.Form("srvName"))

Next I generate a connection string, something like

dbConnect = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;password=password;Initial Catalog=master;Data
Source="&srvName&"."

Then I go on to use the connection string in an ADODB.Connection
object.

It has been quite a while since I worked with classic asp, so this
might just be a bad idea .. :) Please give me a clue if you can!

Thanks

Bob Barrows

unread,
Jul 27, 2009, 6:42:33 PM7/27/09
to
Aside from the use of the sa account, you have it perfect.
Never use the sa account in application code. SA is for Systaem
Administration, and as such, in the wrong hands, could be used to wreak
havoc on a server and network. Always create a limited-permissions account
for use in applications, only granting the permissions needed to perform the
functions required by the application.

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
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"


coolnamewithheld

unread,
Jul 28, 2009, 2:26:04 PM7/28/09
to
On Jul 27, 5:42 pm, "Bob Barrows" <reb01...@NOyahoo.SPAMcom> wrote:
> coolnamewithheld wrote:
> > How do I create a dynamicconnectionstringwith the name of the

> > data source being passed as a variable.
>
> > The way I want this to work is the server name is passed from a
> > classic asp page as a input from a form:
>
> > srvName=trim(Request.Form("srvName"))
>
> > Next I generate a connection string, something like
>
> > dbConnect = "Provider=SQLOLEDB.1;Persist Security Info=False;User
> > ID=sa;password=password;Initial Catalog=master;Data
> > Source="&srvName&"."
>
> > Then I go on to use the connection string in an ADODB.Connection
> > object.
>
> > It has been quite a while since I worked with classic asp, so this
> > might just be a bad idea .. :) Please give me a clue if you can!
>
> Aside from the use of the sa account, you have it perfect.
> Never use the sa account in application code. SA is for Systaem
> Administration, and as such, in the wrong hands, could be used to wreak
> havoc on a server and network. Always create a limited-permissions account
> for use in applications, only granting the permissions needed to perform the
> functions required by the application.

The sa account is just for the example.

The problem I am having is the variable passed using a form on a
previous page, and collected with this:

srvName=""
srvName=trim(Request.Form("srvName"))

I verify that the value of the variable is correct using a print
statement:

response.write("<BR>srvName="&srvName)
response.end

and then render comments when I want to run the page.

However, the value of the variable is not recognized in the
ADODB.Connection object.

When I execute using this connection string:

dbConnect = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;password=password;Initial Catalog=master;Data
Source="&srvName&"."

The connection fails.

If i replace the variable being supplied to Data Source with a hard
coded server name, the connection string does work.

This will not work for me .. I need to have a dynamic connection
string build from user choices. How does one get that to work?

Bob Barrows

unread,
Jul 28, 2009, 2:43:53 PM7/28/09
to

In your hard-coded version, is there a period at the end of the data
source name?

Do a
response.write dbConnect
and compare it with the hard-coded string that works

--
HTH,
Bob Barrows


coolnamewithheld

unread,
Jul 29, 2009, 9:40:42 AM7/29/09
to

That is interesting ... I do not remember why that period was added.
I missed it because I was so sure that there had to be a problem with
the way the variable was being passed, but when I could not find a
problem I was thinking perhaps I was just mis-using the connection
object.

Thanks for the help.

0 new messages