下記コードでSQLServerへ接続しようとすると
ネットワークインターフェイス:指定された Server/Instance の位置を特定しているときにエラーが発生しました
というエラーが発生してしまいます。
ネット等で自分なりに調べてみてはいるのですが、中々うまくいきません。
何かしらアドバイスがいただけたらありがたいです。
Sub Mysql_連続insert() 'ExcelでADO・ADODBへの参照設定で下記をチェック(古いバージョンでも可) 'Microsoft ActiveX 'Data Objects 6.1 Library Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Dim ConnectionString As String Dim sqlStr As String Dim STUDENT As String Dim NAME_S As String Dim NAME_S_F As String Dim NAME_N As String Dim GENDER As String Dim BIRTHDAY_Y As String Dim BIRTHDAY_M As String Dim AGE As String Dim EDUCATION As String Dim GRANDUATIN_Y As String Dim GRANDUATIN_M As String Dim ADDRESS_P As String Dim ADDRESS_T As String Dim ADDRESS_P_F As String Dim ADDRESS_T_F As String Dim NEAREST_L As String Dim NEAREST_S As String '接続文字列 ConnectionString = "Driver={SQL Server Native Client 11.0};" _ & " SERVER= DESKTOP-09F2LJG\SQLEXPRESS" _ & " DATABASE= test" _ & " USER= root" _ & " PASSWORD= root" 'ADODB.Connection生成 Set cn = New ADODB.Connection On Error GoTo Err 'MySQLに接続 cn.Open ConnectionString For i = 2 To 6000 With Sheets("alldata") STUDENT = .Range("C2").Value NAME_S = .Range("D2").Value NAME_S_F = .Range("E2").Value NAME_N = .Range("F2").Value GENDER = .Range("G2").Value BIRTHDAY_Y = .Range("H2").Value BIRTHDAY_M = .Range("I2").Value AGE = .Range("J2").Value EDUCATION = .Range("K2").Value GRANDUATIN_Y = .Range("L2").Value GRANDUATIN_M = .Range("M2").Value ADDRESS_P = .Range("N2").Value ADDRESS_T = .Range("O2").Value ADDRESS_P_F = .Range("P2").Value ADDRESS_T_F = .Range("Q2").Value NEAREST_L = .Range("R2").Value NEAREST_S = .Range("S2").Value End With sqlStr = "insert into BASIC_INFORMATION (STUDENT,NAME_S,NAME_S_F,NAME_N,GENDER,BIRTHDAY_Y,BIRTHDAY_M,AGE,EDUCATION,GRANDUATIN_Y,GRANDUATIN_M,ADDRESS_P,ADDRESS_T,ADDRESS_P_F,ADDRESS_T_F,NEAREST_L,NEAREST_S) values ('" & STUDENT & "','" & NAME_S & "','" & NAME_S_F & "','" & NAME_N & "','" & GENDER & "','" & BIRTHDAY_Y & "','" & BIRTHDAY_M & "','" & AGE & "','" & EDUCATION & "','" & GRANDUATIN_Y & "','" & GRANDUATIN_M & "','" & ADDRESS_P & "','" & ADDRESS_T & "','" & ADDRESS_P_F & "','" & ADDRESS_T_F & "','" & NEAREST_L & "','" & NEAREST_S & "')" Set rs = cn.Execute(sqlStr) Next cn.Close Set rs = Nothing Set cn = Nothing MsgBox "データの登録がおわりました" Exit Sub Err: Set rs = Nothing Set cn = Nothing MsgBox (Err.Description) End Sub
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/07/31 06:58
2020/07/31 07:39
2020/07/31 08:41