连接到SQL数据库时出现VBA运行时错误

时间:2019-10-16 08:27:34

标签: sql excel vba connection

我正在尝试从同一域中的多台PC连接到selectedCategory=snapshot.data[0].id;

使用以下代码时:

SQL Server

Dim conn As ADODB.Connection Set conn = New ADODB.Connection 'Neue Verbindung initialisieren 'Verbindung einrichten' conn.ConnectionString = "PERSIST SECURITY INFO=True;Provider=SQLOLEDB.1;Server=WWDDB;Database=01Projekt;User ID=XXX;Password=XXX;Trusted_Connection=True;Integrated Security=SSPI;" conn.Open 返回错误:

  

用户“ XXXX”的登录错误

2 个答案:

答案 0 :(得分:2)

问题是因为您使用的是Integrated Security命名用户。这两种模式不兼容。

尝试删除Integrated Security=SSPI

conn.ConnectionString = "PERSIST SECURITY INFO=True;Provider=SQLOLEDB.1;Server=WWDDB;Database=01Projekt;User ID=XXX;Password=XXX;Trusted_Connection=True;" conn.Open

或指定的用户:

conn.ConnectionString = "PERSIST SECURITY INFO=True;Provider=SQLOLEDB.1;Server=WWDDB;Database=01Projekt;Trusted_Connection=True;Integrated Security=SSPI;" conn.Open

答案 1 :(得分:0)

这是我的代码段,尝试一下:

var data = File
  .ReadLines(@"C:\temp\Values.csv")
  .Where(line => !string.IsNullOrWhiteSpace(line)) // To be on the safe side
  .Skip(1)                                         // Skip title  
  .Select(line => line.Split(','))                  
  .Select(items => new {
     ID = long.Parse(items[0]), 
     Priority = int.Parse(items[1]), 
     Value = Decimal.Parse(items[2]),
   })
  .OrderBy(item => item.Value)    // order by Value
  .ThenBy(item => item.Priority)  // ! In case of tie, order by priority
  .Select(item => $"{item.ID},{item.Priority},{item.Value}"); 

File
  .WriteAllLines(@"C:\temp\sorted.csv", new string[] {
     "ID", "Priority", "Value"}.Concat(data)
);