Re: escaping semi colon in connectionstring



This works for me ...

Public Sub TestSub()

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset

Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=SQLOLEDB.1;" & _
"Integrated Security=SSPI;Persist Security Info=False;" & _
"Initial Catalog=" & Chr$(34) & "test;name" & Chr$(34) & _
";Data Source=(local)"
cnn.Open
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = cnn
.Source = "SELECT * FROM dbo.authors"
.Open
Debug.Print .Fields(0).Value
.Close
End With
cnn.Close

End Sub

--
Brendan Reynolds (MVP)

"Ajey" <ajey5@xxxxxxxxxxx> wrote in message
news:ue3NQ6YdFHA.3488@xxxxxxxxxxxxxxxxxxxxxxx
>I tried using double quotes. I doesn't work.
>
>
> "Daniel Crichton" <msnews@xxxxxxxxxxxxxxxxxx> wrote in message
> news:uahMbvmcFHA.1040@xxxxxxxxxxxxxxxxxxxxxxx
>> Ajey wrote on Thu, 16 Jun 2005 14:42:35 +0530:
>>
>>> Hi,
>>> I created a database having ; in name e.g. abc;def
>>> Now, while connecting to this database using ADO I am getting
>>> "Invalid connection string attribute" error. How can I escape semicolon
>>> in
>>> connection string.
>>>
>>> Connection string:
>>>
>>> Provider=SQLOLEDB;Server=S1;Database=abc;def;Trusted_Connection=NO;User
>>> Id=a;Password=a;
>>>
>>
>> From
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlConnectionClassConnectionStringTopic.asp
>>
>> "To include values that contain a semicolon, single-quote character, or
>> double-quote character, the value must be enclosed in double quotes"
>>
>> so try
>>
>> Provider=SQLOLEDB;Server=S1;Database="abc;def";Trusted_Connection=NO;User
>> Id=a;Password=a;
>>
>>
>> Dan
>>
>
>


.



Relevant Pages

  • Re: escaping semi colon in connectionstring
    ... escape every single quote with two single quotes. ... > Dim cnn As ADODB.Connection ... > Dim rst As ADODB.Recordset ... > Set cnn = New ADODB.Connection ...
    (microsoft.public.data.ado)
  • Re: Error# -2147467259 in ado for accesss 2000
    ... Dim rst As New ADODB.Recordset ... > Dim rst As New ADODB.Recordset ... > 'Set Cnn = New ADODB.Connection ... >>> connection, close the recordset and finally the connection. ...
    (microsoft.public.access.formscoding)
  • RE: How can I use VBA ADO to check if a table exists in an Access DB?
    ... Dim cnn As New ADODB.Connection ... Dim rsT As ADODB.Recordset ... Dim Verif As Boolean ... Set cnn = New Connection ...
    (microsoft.public.excel.programming)
  • Re: Connection cannot be used
    ... >I get this error message when trying to open my connection string: ... > Dim cnn, rst ... > Dim sConnString ... > msodsc.SetRootRecordset "totalClients", rst ...
    (microsoft.public.access.dataaccess.pages)
  • Suche Funktion für DS-Gruppen-Ergebnis
    ... Private Function AllFalse() as Boolean ... Dim rst as ADODB.Recordset ... Set rst = New Recordset ... Set cnn = CurrentProject.Connection ...
    (microsoft.public.de.access)