title: Connecting to Sql Server Database with hyphenated name
body: <p>I don't seem to be able to find a way to escape this hyphenated database name so that I can open a connection to it.  The database name is <code>EDMS-Lok</code> and my code looks like this (ADOcon is an ADO connection object):   </p>
  
  <pre><code>strConBase="DRIVER=SQL Server;SERVER=LOKDB;UID=secret;PWD=secret;APP=LokENG_TESTS;WSID=LOKSPEC1;DATABASE=[EDMS-Lok];Network=DBMSSOCN;Trusted_Connection=NO;
  ADOcon.ConnectionString = strConBase
  ADOcon.Open"
  </code></pre>
  
  <p>I've tried the database name without enclosing brackets.  I've tried enclosing it in square brackets, curly brackets, parentheses, back-ticks, single quotes, double quotes, etc.  I've tried backslash and exclamation points.  I can't find a way to escape the database name so that I can connect to it.  </p>
  
  <p>The error message I get is:<br>
  <code>Run-time error '-2147467259 (80004005)': 
  [Microsoft][ODBS SQL Server Driver][SQL Server]Cannot open database "[EDMS-Lok]" requested by the login.  The login failed.</code></p>
  
  <p>The database name and credentials are correct. I can access it if I omit the database name argument from the connection string, and then use the fully qualified name in my SQL statements (i.e. <code>SELECT * FROM [EDMS-Lok].dbo.tablename</code>)</p>
  
  <p>However, I really don't want to do this, as I'm trying to use modular code that does the same actions on multiple databases. What I want is to open the connection to one database, run some SQL procedures, close the connection, then open a connection to another database and run the same SQL procedures.  Lather, rinse, repeat. </p>
  
  <p>Also, before someone asks, I do not have the option of changing the database name.  </p>
  
  <p>As a test, I used the exact same connection string to connect to another database on the server that did not have a hyphenated name and it worked without error, so I'm pretty sure it's the stupid hyphenated name that is the problem. </p>