diff -aburN --exclude='CVS*' phpgwapi.org/inc/class.contacts_ldap.inc.php phpgwapi/inc/class.contacts_ldap.inc.php
--- phpgwapi.org/inc/class.contacts_ldap.inc.php	2005-10-02 14:31:19.123526400 +0200
+++ phpgwapi/inc/class.contacts_ldap.inc.php	2005-10-02 14:33:02.071558400 +0200
@@ -649,7 +649,7 @@
 				while (list($name,$value) = each($extra_fields))
 				{
 					$this->db->query("INSERT INTO $this->ext_table VALUES ('".$this->nextid."','" . $this->account_id . "','"
-						. addslashes($name) . "','" . addslashes($value) . "')",__LINE__,__FILE__);
+						. $this->db->db_addslashes($name) . "','" . $this->db->db_addslashes($value) . "')",__LINE__,__FILE__);
 				}
 			}
 			return $this->nextid;
@@ -658,21 +658,21 @@
 		function field_exists($id,$field_name)
 		{
 			$this->db->query("select count(*) from $this->ext_table where contact_id='$id' and contact_name='"
-			. addslashes($field_name) . "'",__LINE__,__FILE__);
+			. $this->db->db_addslashes($field_name) . "'",__LINE__,__FILE__);
 			$this->db->next_record();
 			return $this->db->f(0);
 		}
 
 		function add_single_extra_field($id,$owner,$field_name,$field_value)
 		{
-			$this->db->query("insert into $this->ext_table values ($id,'$owner','" . addslashes($field_name)
-			. "','" . addslashes($field_value) . "')",__LINE__,__FILE__);
+			$this->db->query("insert into $this->ext_table values ($id,'$owner','" . $this->db->db_addslashes($field_name)
+			. "','" . $this->db->db_addslashes($field_value) . "')",__LINE__,__FILE__);
 		}
 
 		function delete_single_extra_field($id,$field_name)
 		{
 			$this->db->query("delete from $this->ext_table where contact_id='$id' and contact_name='"
-			. addslashes($field_name) . "'",__LINE__,__FILE__);
+			. $this->db->db_addslashes($field_name) . "'",__LINE__,__FILE__);
 		}
 
 		function update($id,$owner,$fields,$access='private',$cat_id='0',$tid='n')
@@ -824,8 +824,8 @@
 						}
 						else
 						{
-							$this->db->query("UPDATE $this->ext_table SET contact_value='" . addslashes($x_value)
-							. "',contact_owner='$owner' WHERE contact_name='" . addslashes($x_name)
+							$this->db->query("UPDATE $this->ext_table SET contact_value='" . $this->db->db_addslashes($x_value)
+							. "',contact_owner='$owner' WHERE contact_name='" . $this->db->db_addslashes($x_name)
 							. "' AND contact_id='$id'",__LINE__,__FILE__);
 						}
 					}
diff -aburN --exclude='CVS*' phpgwapi.org/inc/class.db_mssql.inc.php phpgwapi/inc/class.db_mssql.inc.php
--- phpgwapi.org/inc/class.db_mssql.inc.php	2005-10-02 14:31:19.133540800 +0200
+++ phpgwapi/inc/class.db_mssql.inc.php	2005-10-02 15:40:38.522987200 +0200
@@ -65,6 +65,11 @@
 			}
 		}
 
+		function disconnect()
+		{
+			mssql_close($this->Link_ID);
+		}
+
 		function db_addslashes($str)
 		{
 			if (!IsSet($str) || $str == '')
@@ -121,6 +126,10 @@
 				$num_rows = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
 			}
 
+			$Query_String = str_replace('SELECT ', 'SELECT TOP ', $Query_String);
+			$Query_String = str_replace('SELECT TOP DISTINCT', 'SELECT DISTINCT TOP ', $Query_String);
+			$Query_String = str_replace('TOP ', 'TOP ' . ($offset + $num_rows) . ' ', $Query_String);
+
 			if ($this->Debug)
 			{
 				printf("Debug: limit_query = %s<br />offset=%d, num_rows=%d<br />\n", $Query_String, $offset, $num_rows);
@@ -253,7 +262,7 @@
 		{
 			if($this->Query_ID)
 			{
-				return mssql_num_rows($this->Query_ID);
+				return $this->affected_rows();
 			}
 			else
 			{
@@ -270,11 +279,11 @@
 		{
         	if ($strip_slashes || ($this->auto_stripslashes && ! $strip_slashes))
 			{
-				return str_replace("''", "'", $this->Record[$Name]);
+				return str_replace("''", "'", $this->Record[$Field_Name]);
 			}
 			else
 			{
-				return $this->Record[$Name];
+				return $this->Record[$Field_Name];
 			}
 		}
 
@@ -306,7 +315,7 @@
 
 		function halt($msg, $line = '', $file = '')
 		{
-			$this->unlock();
+			$this->transaction_abort();
 
 			$this->Errno = 1;
 			$this->Error = mssql_get_last_message();
@@ -335,7 +344,6 @@
 			if ($this->Halt_On_Error != "report")
 			{
 				echo "<p><b>Session halted.</b>";
-				$this->transaction_abort();
 				$GLOBALS['phpgw']->common->phpgw_exit(True);
 			}
 		}
diff -aburN --exclude='CVS*' phpgwapi.org/inc/class.historylog.inc.php phpgwapi/inc/class.historylog.inc.php
--- phpgwapi.org/inc/class.historylog.inc.php	2005-10-02 14:31:19.143555200 +0200
+++ phpgwapi/inc/class.historylog.inc.php	2005-10-02 14:33:02.081572800 +0200
@@ -53,7 +53,7 @@
 					. "history_appname,history_owner,history_status,history_new_value,history_old_value,history_timestamp) "
 					. "values ('".intval($record_id)."','" . $this->appname . "','"
 					. $GLOBALS['phpgw_info']['user']['account_id'] . "','$status','"
-					. addslashes($new_value) . "','" . addslashes($old_value) . "','" . $this->db->to_timestamp(time())
+					. $this->db->db_addslashes($new_value) . "','" . $this->db->db_addslashes($old_value) . "','" . $this->db->to_timestamp(time())
 					. "')",__LINE__,__FILE__);
 			}
 		}
diff -aburN --exclude='CVS*' phpgwapi.org/inc/class.log.inc.php phpgwapi/inc/class.log.inc.php
--- phpgwapi.org/inc/class.log.inc.php	2005-10-02 14:31:19.153569600 +0200
+++ phpgwapi/inc/class.log.inc.php	2005-10-02 14:33:02.091587200 +0200
@@ -78,13 +78,13 @@
 			}
 			
 			if (    ( isset($GLOBALS['phpgw_info']['flags']['currentapp']) )
-			     && ( array_key_exists( $GLOBALS['phpgw_info']['flags']['currentapp'] , $GLOBALS['phpgw_info']['server']['log_levels']['module']) )
+			     && ( @array_key_exists( $GLOBALS['phpgw_info']['flags']['currentapp'] , $GLOBALS['phpgw_info']['server']['log_levels']['module']) )
 			     && ( $this->log_level_table[$GLOBALS['phpgw_info']['server']['log_levels']['module'][$GLOBALS['phpgw_info']['flags']['currentapp']]] >= $this->log_level_table[$level] ) ) {
 					return true;
 			}
 			
 			if (    ( isset($GLOBALS['phpgw_info']['user']['account_lid']) )
-				 && ( array_key_exists($GLOBALS['phpgw_info']['user']['account_lid'], $GLOBALS['phpgw_info']['server']['log_levels']['user']) )
+				 && ( @array_key_exists($GLOBALS['phpgw_info']['user']['account_lid'], $GLOBALS['phpgw_info']['server']['log_levels']['user']) )
 			     && ( $this->log_level_table[$GLOBALS['phpgw_info']['server']['log_levels']['user'][$GLOBALS['phpgw_info']['user']['account_lid']]] >= $this->log_level_table[$level] ) ) {
 				return true;
 			}
diff -aburN --exclude='CVS*' phpgwapi.org/inc/class.preferences.inc.php phpgwapi/inc/class.preferences.inc.php
--- phpgwapi.org/inc/class.preferences.inc.php	2005-10-02 14:31:19.163584000 +0200
+++ phpgwapi/inc/class.preferences.inc.php	2005-10-02 14:33:02.101601600 +0200
@@ -464,7 +464,7 @@
 		{
 			if (!is_array($arr))
 			{
-				$arr = addslashes($arr);
+				$arr = $this->db->db_addslashes($arr);
 				return;
 			}
 			foreach($arr as $key => $value)
@@ -475,7 +475,7 @@
 				}
 				else
 				{
-					$arr[$key] = addslashes($value);
+					$arr[$key] = $this->db->db_addslashes($value);
 				}
 			}
 		}
@@ -517,7 +517,7 @@
 				{
 					if (!is_array($value)) continue;
 					$this->quote($value);
-					$value = addslashes(serialize($value));	// this addslashes is for the database
+					$value = $this->db->db_addslashes(serialize($value));	// this addslashes is for the database
 					$app = $this->db->db_addslashes($app);
 					
 					$this->db->query($sql = "INSERT INTO phpgw_preferences".
diff -aburN --exclude='CVS*' phpgwapi.org/inc/class.schema_proc.inc.php phpgwapi/inc/class.schema_proc.inc.php
--- phpgwapi.org/inc/class.schema_proc.inc.php	2005-10-02 14:31:19.173598400 +0200
+++ phpgwapi/inc/class.schema_proc.inc.php	2005-10-02 14:33:02.111616000 +0200
@@ -425,6 +425,10 @@
 				{
 					$sFieldSQL .= ' NOT NULL';
 				}
+				else
+				{
+					$sFieldSQL .= ' NULL';
+				}
 				
 				if($sDefault == '0')
 				{
diff -aburN --exclude='CVS*' phpgwapi.org/inc/class.schema_proc_mssql.inc.php phpgwapi/inc/class.schema_proc_mssql.inc.php
--- phpgwapi.org/inc/class.schema_proc_mssql.inc.php	2005-10-02 14:31:19.173598400 +0200
+++ phpgwapi/inc/class.schema_proc_mssql.inc.php	2005-10-02 14:33:02.111616000 +0200
@@ -326,7 +326,7 @@
 		function GetSequenceSQL($sTableName, &$sSequenceSQL)
 		{
 			$sSequenceSQL = '';
-			return true;
+			return false;
 		}
 
 		function CreateTable($oProc, &$aTables, $sTableName, $aTableDef)
@@ -345,5 +345,10 @@
 
 			return false;
 		}
+
+		function GetFKSQL($sFields)
+		{
+			return false;
+		}
 	}
 ?>
diff -aburN --exclude='CVS*' phpgwapi.org/inc/class.setup.inc.php phpgwapi/inc/class.setup.inc.php
--- phpgwapi.org/inc/class.setup.inc.php	2005-10-02 14:31:19.183612800 +0200
+++ phpgwapi/inc/class.setup.inc.php	2005-10-02 14:33:02.121630400 +0200
@@ -320,27 +320,9 @@
 			}
 			$enable = intval($enable);
 
-			/*
-			Use old applications table if the currentver is less than 0.9.10pre8,
-			but not if the currentver = '', which probably means new install.
-			*/
-			if($this->alessthanb($setup_info['phpgwapi']['currentver'],'0.9.10pre8') && ($setup_info['phpgwapi']['currentver'] != ''))
-			{
-				$appstbl = 'applications';
-			}
-			else
-			{
-				$appstbl = 'phpgw_applications';
-				if($this->amorethanb($setup_info['phpgwapi']['currentver'],'0.9.13.014'))
-				{
-					$use_appid = True;
-				}
-			}
-
 			if($GLOBALS['DEBUG'])
 			{
-				echo '<br />register_app(): ' . $appname . ', version: ' . $setup_info[$appname]['version'] . ', table: ' . $appstbl . '<br />';
-				// _debug_array($setup_info[$appname]);
+				echo '<br>register_app(): ' . $appname . ', version: ' . $setup_info[$appname]['version'] . ', table: phpgw_applications<br>';
 			}
 
 			if($setup_info[$appname]['version'])
@@ -360,26 +342,9 @@
 						.$appname."_tables_prefix','".$setup_info[$appname]['tables_prefix']."')";
 					$this->db->query($sql,__LINE__,__FILE__);
 				}
-				if($use_appid)
-				{
-					$this->db->query("SELECT MAX(app_id) FROM $appstbl",__LINE__,__FILE__);
-					$this->db->next_record();
-					if($this->db->f(0))
-					{
-						$app_id = ($this->db->f(0) + 1) . ',';
-						$app_idstr = 'app_id,';
-					}
-					else
-					{
-						srand(100000);
-						$app_id = rand(1,100000) . ',';
-						$app_idstr = 'app_id,';
-					}
-				}
-				$this->db->query("INSERT INTO $appstbl "
-					. "($app_idstr app_name,app_enabled,app_order,app_tables,app_version) "
+				$this->db->query("INSERT INTO phpgw_applications "
+					. "(app_name,app_enabled,app_order,app_tables,app_version) "
 					. "VALUES ("
-					. $app_id
 					. "'" . $setup_info[$appname]['name'] . "',"
 					. $enable . ","
 					. intval($setup_info[$appname]['app_order']) . ","
diff -aburN --exclude='CVS*' phpgwapi.org/inc/functions.inc.php phpgwapi/inc/functions.inc.php
--- phpgwapi.org/inc/functions.inc.php	2005-10-02 14:31:19.193627200 +0200
+++ phpgwapi/inc/functions.inc.php	2005-10-02 14:33:02.131644800 +0200
@@ -207,7 +207,7 @@
 				$GLOBALS['phpgw']->db->query($cache_query,__LINE__,__FILE__);				
 			}
 			$cache_query = 'INSERT INTO phpgw_app_sessions(sessionid,loginid,app,location,content) VALUES('
-				. "'0','0','phpgwapi','config','".addslashes(serialize($GLOBALS['phpgw_info']['server']))."')";
+				. "'0','0','phpgwapi','config','". $GLOBALS['phpgw']->db->db_addslashes(serialize($GLOBALS['phpgw_info']['server']))."')";
 			$GLOBALS['phpgw']->db->query($cache_query,__LINE__,__FILE__);
 		}
 	}
diff -aburN --exclude='CVS*' phpgwapi.org/setup/tables_update.inc.php phpgwapi/setup/tables_update.inc.php
--- phpgwapi.org/setup/tables_update.inc.php	2005-10-02 14:31:19.203641600 +0200
+++ phpgwapi/setup/tables_update.inc.php	2005-10-02 14:33:02.141659200 +0200
@@ -673,7 +673,7 @@
 				{
 					if (!empty($app) && count($pref))
 					{
-						$app = addslashes($app);
+						$app = $GLOBALS['phpgw_setup']->db->db_addslashes($app);
 						$pref = serialize($pref);
 						$db2->query("INSERT INTO phpgw_preferences".
 							" (preference_owner,preference_app,preference_value)".
