1С77, Соединение с SQL-Server, Подключение к SQL-Server, ADODB, Connection, Recordset, ActiveConnection, Прямой SQL-запрос к базе, Обход рекордсета
Server = "ServerName"; //Имя сервера
DataBase = "DBName"; //Имя базы данных
Login = "sa"; //Логин
Password = "secretpsw"; //Пароль
Connection = CreateObject("ADODB.Connection");
DataBase = "DBName"; //Имя базы данных
Login = "sa"; //Логин
Password = "secretpsw"; //Пароль
Connection = CreateObject("ADODB.Connection");
ConnectionString = "driver={SQL Server};"+"server="+СокрЛП(Server)+";"+"uid="+СокрЛП
(Login)+"; "+"pwd="+СокрЛП(Password)+";"+"Database="+СокрЛП(Database);
Connection.ConnectionTimeOut = 600;
Connection.CommandTimeout = 300;
Connection.Open(ConnectionString);
Payments = CreateObject("ADODB.RecordSet");
Payments.ActiveConnection = Connection;
strQuery = "
| SELECT Field1, Field2
| FROM Payments
|";
Payments.Open(strQuery);
While Payments.EOF = 0 Do
Сообщить(Payments.Fields("Field1").Value);
Сообщить(Payments.Fields("Field2").Value);
Payments.MoveNext();
EndDo;
Payments.Close();
ПустоеЗначение(Payments);
Connection.Close();
ПустоеЗначение(Connection);
Connection.ConnectionTimeOut = 600;
Connection.CommandTimeout = 300;
Connection.Open(ConnectionString);
Payments = CreateObject("ADODB.RecordSet");
Payments.ActiveConnection = Connection;
strQuery = "
| SELECT Field1, Field2
| FROM Payments
|";
Payments.Open(strQuery);
While Payments.EOF = 0 Do
Сообщить(Payments.Fields("Field1").Value);
Сообщить(Payments.Fields("Field2").Value);
Payments.MoveNext();
EndDo;
Payments.Close();
ПустоеЗначение(Payments);
Connection.Close();
ПустоеЗначение(Connection);