Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 372
  • Last Modified:

MS-SQL connect fails on a database with a hyphen in the name.

Hi there,

I am using mssql_select_db as part of ADODB 4.5.3 under PHP 4.3.9 on windows XPsp1

I have modified the SelectDb method to echo out some parameters as it goes...

Attepting connection to uk-argo-asp-01_LM_W3SVC_1_Collab
ConnectionID = Resource id #7
calling mssql_select_db('uk-argo-asp-01_LM_W3SVC_1_Collab')

Then the mssql_select_db(...) is called and this error is outputted with connection debug on.

127.1.1.104: Could not locate entry in sysdatabases for database 'uk'. No entry found with that name. Make sure that the name is entered correctly.

My connection to, and credentials on the database are sound as I can connect to the Northwind database (with a different erro regarding ODBC version and ntext).

The problem is that the mssql_... appears to be truncating the name. However, I did have ADODB version 2.42 and this did not appear to happen, but I am forced to upgrade as I require funcionality in the new version.

Any ideas how I can escape the name, or fix the problem?

Thanks in advance.
0
nigel5
Asked:
nigel5
  • 3
1 Solution
 
minichickenCommented:
some guessing work: use [] brackets

mssql_select_db('[uk-argo-asp-01_LM_W3SVC_1_Collab]')


0
 
nigel5Author Commented:
Oh, I have also loaded the latest MDAC (2.8)
0
 
nigel5Author Commented:
The brackets doesn't work...

calling mssql_select_db('[uk-argo-asp-01_LM_W3SVC_1_Collab]')
127.1.1.104: Line 1: Incorrect syntax near 'uk-argo-asp-01_LM_W3SVC_1_Col'.

Another stab in the dark was double quotes, as exepected no difference.
0
 
nigel5Author Commented:
I have found the answer...

DSN-less connection via ODBC...

  $db_name = "uk-argo-asp-01_LM_W3SVC_1_Collab";
  $server = "localhost";
  $dsn = "Driver={SQL Server};Server=$server;Database=$db_name;";
  $mssqlconn = &ADONewConnection('odbc');
  $mssqlconn->Connect($dsn, $db_user, $db_pass);
0
 
Computer101Commented:
PAQed with points refunded (125)

Computer101
EE Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now