23. oktober 2008 - 13:14Der er
6 kommentarer og 2 løsninger
Åbne forbindelse far Access til SQL Server
Jeg har tidligere åbnet en forbindelse fra Access til en Oracle database på følgende måde:
Public Conn As New ADODB.Connection Conn.Open "Provider=MSDAORA;Data Source=sourcenavn", "user", "password"
og det gik fint nok.
Nu skal jeg i stedet åbne en forbindelse til en SQL server, hvor de samme tabeller ligger, men det kan jeg ikke få til at virke! Jeg har servernavn, database, brugenavn og password til SQL serveren, men hvordan skal syntaksen være?
Teknologi, AI og forretning er i centrum på Computerworlds Cloud og AI Festival i København d. 18. og 19. september. Se hele programmet for den store konference om strategisk brug af Cloud og AI på: www.cloud-festival.dk
I have tried it and now it tells me that the server does not exist or access not allowed (another error than before). I have contacted our IT department as I can make connection with a Visual Studio project with the same information. I will let you know.
Function AttachDSNLessTable(stLocalTableName As String, stRemoteTableName As String, stServer As String, stDatabase As String, Optional stUsername As String, Optional stPassword As String) On Error GoTo AttachDSNLessTable_Err Dim td As TableDef Dim stConnect As String
For Each td In CurrentDb.TableDefs If td.Name = stLocalTableName Then CurrentDb.TableDefs.Delete stLocalTableName End If Next
If Len(stUsername) = 0 Then '//Use trusted authentication if stUsername is not supplied. stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";Trusted_Connection=Yes" Else '//WARNING: This will save the username and the password with the linked table information. stConnect = "ODBC;DRIVER=SQL Server;SERVER=" & stServer & ";DATABASE=" & stDatabase & ";UID=" & stUsername & ";PWD=" & stPassword End If Set td = CurrentDb.CreateTableDef(stLocalTableName, dbAttachSavePWD, stRemoteTableName, stConnect) CurrentDb.TableDefs.Append td AttachDSNLessTable = True Exit Function
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.