Форум: "Базы";
Текущий архив: 2004.05.30;
Скачать: [xml.tar.bz2];
ВнизМожно ли программно в ODBC прописывать DSN??? Найти похожие ветки
← →
Andrew Frol (2004-05-08 12:24) [0]Если да, то как? Подскажите!
← →
sniknik © (2004-05-08 12:41) [1]
procedure TForm1.Button1Click(Sender: TObject);
const
keyODBC = "\SOFTWARE\ODBC\ODBC.INI\";
keyODBCINST = "\SOFTWARE\ODBC\ODBCINST.INI\";
keyODBCDrivers = keyODBCINST + "ODBC Drivers\";
keySQLServer = "SQL Server";
keyODBCDataSrcs = "ODBC Data Sources";
vdInstalled = "Installed";
vnDriver = "Driver";
vnDataBase = "DataBase";
vnDescription = "Description";
vnLastUser = "LastUser";
vnServer = "Server";
NewDNSName : string = "NewDNSName";
DataBase : string = "master";
Description : string = "UAIGORS SQL Server";
LastUser : string = "sa";
Server : string = "UAIGORS";
Driver : string = "sqlsrv32.dll";
var
Reg : TRegistry;
begin
Reg := TRegistry.Create;
with Reg do
try
RootKey := HKEY_LOCAL_MACHINE;
if OpenKey(keyODBC, False) and OpenKey(keyODBCINST, False) then
begin
if OpenKey(keyODBCDrivers, False) then
if ReadString(keySQLServer) = vdInstalled then
begin
if not KeyExists(keyODBC + "\" + NewDNSName) then
begin
if OpenKey(keyODBCINST + "\" + keySQLServer, False) then
Driver := ReadString(vnDriver);
if CreateKey(keyODBC + "\" + NewDNSName) then
begin
OpenKey(keyODBC + "\" + NewDNSName, False);
WriteString(vnDataBase, DataBase);
WriteString(vnDescription, Description);
WriteString(vnDriver, Driver);
WriteString(vnLastUser, LastUser);
WriteString(vnServer, Server);
if OpenKey(keyODBC + "\" + keyODBCDataSrcs, False) then WriteString(NewDNSName, keySQLServer);
end
else
MessageBox(0, PChar("Can not create new registry key: "+NewDNSName), "Warning", MB_ICONWARNING);
end
else
MessageBox(0, "This DNS name already exists", "Warning", MB_ICONWARNING);
end
else
MessageBox(0, "SQL Server driver not installed", "Warning", MB_ICONWARNING);
end
else
MessageBox(0, "ODBC not installed", "Warning", MB_ICONWARNING);
finally
Reg.Free;
end;
end;
← →
Andrew Frol (2004-05-08 12:51) [2]Все ясно. Огромное спасибо!
← →
KSergey © (2004-05-10 09:56) [3]См. ф-цию SQLConfigDataSource
Пример ее использования можно найти тут
http://delphibase.endimus.ru/?action=viewfunc&topic=basemssql&id=10442
Страницы: 1 вся ветка
Форум: "Базы";
Текущий архив: 2004.05.30;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.6 c