2
我有以下的VBA代碼,我收到了這個問題標題中指出的錯誤信息。任何人都可以幫忙嗎?我通常不會寫這種代碼:VBA連接到SQL Server數據源名稱未找到並且沒有指定默認驅動程序?
Sub Save_To_DB()
'Declare some variables
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim strSQL As String
'Create a new Connection object
Set cnn = New ADODB.Connection
'Set the connection string
cnn.ConnectionString = "Server=server_name;Database=database_name;Trusted_Connection=True;"
'Open the Connection to the database
cnn.Open **<-THE ERROR THROWS HERE**
'Create a new Command object
Set cmd = New ADODB.Command
'Associate the command with the connection
cmd.ActiveConnection = cnn
'Go on to write the SQL statement and execute
編輯:好的我解決了它,包括在連接字符串中Driver={SQL Native Client};
需要。
嗨Remou,我使用的網站,但有似乎有很多不同的方式來指定它。你能舉一個你知道有效的例子嗎? – mezamorphic 2012-03-02 12:10:12
我的連接字符串到SQL服務器不會爲你工作。你需要知道關於你自己的服務器的事情,在這裏發佈它不是一個好主意。但是,我會在我的答案中添加一個註釋。 – Fionnuala 2012-03-02 12:15:35