MSSQL, ODBC connection - how to use? lazarus / 16-Databases ---------------------------------------------------------------------- wht244 · 2010-03-23 19:16 i try to use an ODBCConnection, but it doesn't work. i try the code: Quote  try     m_ODBCConnection := TODBCConnection.Create(nil);     m_SQLTransaction := TSQLTransaction.Create(nil);     m_SQLQuery:=TSQLQuery.Create(nil);     with m_SQLTransaction do     begin       DataBase := m_ODBCConnection;       Active := false;     end;     with m_ODBCConnection do     begin       KeepConnection:=false;       LoginPrompt:=false;       Driver := 'SQL Server';       DatabaseName:='db';       UserName:= 'sa';       Password:='password';       Transaction:=m_SQLTransaction;       Connected:=true;     end;     with m_SQLQuery do     begin       DataBase := m_ODBCConnection;       ParseSQL := false;       Transaction := m_SQLTransaction;       SQL.Clear;       SQL.Add('SELECT (2 + 2) AS tmps');       Open;     end;     if not m_SQLQuery.EOF then       ShowMessage(m_SQLQuery.FieldByName('tmps').AsString);   except     on E:Exception do     begin       ShowMessage(E.Message);       Exit;     end;   end; what's wrong? the exception i receive is: QuoteCould not connect with connection string "DSN=db;DRIVER=SQL Server;UID=sa;PWD=password;". ODBC error details: LastReturnCode: SQL_ERROR; Record 1: SqlState: IM002; NativeError: 0; Message: [Microsoft][Mened?er sterownik?w ODBC] Nie mo?na odnale?? nazwy ?r?d?a danych, a nie ma podanego sterownika domy?lnego;last sentence in translation: QuoteCannot find Data Source Name, and no default driver is given. ---------------------------------------------------------------------- thierrybo · 2010-03-23 21:40 I think you did not set Where is the server ('server'). Here is what works for me for SQL Server 2008. Code: [Select]    with ODBCConnection1 do     begin          Driver := 'SQL Server Native Client 10.0';          Params.Add('Trusted_Connection=Yes');          Params.Add('MARS_Connection=YES');          Params.Add('DATABASE=PHILDELS');          Params.Add('SERVER=TEST-026BB19C4F');          Connected:= true;     end;     with SQLQuery1 do     begin       ParseSQL := false;       SQL.Clear;       SQL.Add('SELECT * from annuaire0');       Open;     end; ---------------------------------------------------------------------- Lacak2 · 2010-03-24 05:48 Check in Control Panel / ODBC Manager, that there is defined DataSource with name "db" See also http://wiki.lazarus.freepascal.org/ODBCConn ---------------------------------------------------------------------- wht244 · 2010-03-24 06:27 thierrybo: that doesn't work for me... Lacak2: i don't have that applet in control panel ---------------------------------------------------------------------- thierrybo · 2010-03-24 12:06 Hi, All windows versions have this applet in control Panel. Read again the wiki link, it's explained where to find the applet in control panel. I think you should try to create an ODBC source manually and test the connexion with this applet before trying to use ODBC in Lazarus.