Re: dynamic connection string

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Jul 27, 5:42 pm, "Bob Barrows" <reb01...@xxxxxxxxxxxxxxx> 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?

.



Relevant Pages

  • Re: Mining Model process with sql server 2005
    ... I'd like to add that there are a few potential places where account ... The data source account will be a windows account, and the connection ... > connection string contains a SQL username and password, ...
    (microsoft.public.sqlserver.datamining)
  • Re: Problems accessing the ASPNETDB.MDF file
    ... I have no connection string to in my config ... Nicole Calinoiu wrote: ... If you can't use IIS Manager on the server, you can access the account ...
    (microsoft.public.dotnet.security)
  • RE: OWC 11 security problem connecting to AS
    ... only set the anonymous access for this virtual directory and grant the ... account to the anonymous access: ... Then change the data source of the pivottable control in the ...
    (microsoft.public.office.developer.web.components)
  • Re: Data Source Provider Error
    ... It doesn't matter if your interactive account has access to the data or not. ... The actual processing work is done by the server itself. ... connections in your data source, then what counts is what logon account the ...
    (microsoft.public.sqlserver.olap)
  • MailMerge with SQL Server, OpenDataSource problem
    ... Attaches the specified data source to the active document, ... Microsoft Query file instead of a specifying a data source, ... connection string, and a query string. ...
    (microsoft.public.office.developer.automation)