Freitag, Juli 1st, 2011 | by Andreas Bruckner | Posted in SQL 2008 | No Comments »
Anybody ever tried to search in ntext or text fields on MS SQL Server?
Common experience is to fail.
Solution: cast your search-term to text type, and try again.
Example, using EA-Database:
SELECT * FROM t_xref x
WHERE x.Description LIKE CAST(‘%GUID={761F0C9E-92E4-42d1-8F0A-D3740A2BFF60}%’ AS TEXT)
Dienstag, Februar 15th, 2011 | by Franz Kalchmair | Posted in .NET Framework, C#, IIS, LINQ2SQL, Open Components Framework, SQL 2008, Visual Studio | No Comments »
Im ersten Teil „Business Solutions entwickeln mit OCF“ wurde beschrieben, wie einfach man zu einem fertigen Grundgerüst für eine Business Solution kommt und wie man mit Hilfe des Entity Wizard alle benötigten Klassen für einen neuen Businessobjekttyp bekommt.
Die konkrete Implementierung einer beispielhaften Businesslogik ist das Thema dieses Artikels. Mit OCF lässt sich jede Art von Businesslogik umsetzen, jedoch wird die Umsetzung von Anwendungen für den Verwaltungssektor besonders unterstützt. Im letzten Artikel wurde schon kurz beschrieben, welche Entity Typen der Wizard anbietet. Businessobject, BaseDocument und Businesscase sind Typen, die in eGov-Fachanwendungen sehr häufig vorkommen. Businessobject ist das Basisobjekt eines jeden Geschäftsobjektes, enthält u.a. ein Property Identificationstring zur Darstellung der Aktenzahl bzw. Geschäftszahl. BaseDocument und Businesscase (Geschäftsfall) sind Ableitungen.
Im Beispiel werden 2 Entities erzeugt: File (Akt) und Document. File wird auf Basis des Entity Typs „Archive Object“ erzeugt, Document mit „Base Document“. Document erhält zusätzlich noch einen Foreign Key, der auf „File“ verweist.

Damit erhält man alle benötigten Klassen.
Im Design Modus des LinqToSql Mapping Files „Entities.dbml“ fügt man jetzt manuell eine Association zwischen „File“ und „Document“ ein. Damit wird „File“, also der „Akt“, zum Container für Dokumente. Ein typischer Use Case im Verwaltungsbereich.

Als nächstes folgen ein paar notwendige Anpassungen. Der DataContract „File“ muss um ein Property „Documents“ erweitert werden.

Die Klasse “FileTranslator”, die das Business Entity „File“ in den DataContract „File“ übersetzt, muss ebenfalls angepasst werden, damit etwa beim Abfragen eines Aktes die verlinkten Dokumente gleich mitgeliefert werden.

Damit sind die Vorbereitungen fertig und man kann die Service Methoden implementieren, beispielhaft die Methoden „CreateFile“, „CreateDocument“ und „GetFileByID“.
Dazu öffnet man das Interface „IBusinessService“ im Contracts-Projekt und ergänzt die Methoden.

Die Implementierung des ServiceContracts könnte so aussehen:

Damit ist die Implementierung der Businesslogik fertig. Nach dem Update der Service Referenz im Client-Projekt, kann man auf die Service Methoden zugreifen und ein kleines Testprogramm schreiben.

Damit hat man bereits das Grundgerüst einer „ELAK konformen Fachanwendung“. Eine interessante Erweiterung des Beispiels wäre die Anbindung an den Dms Service Ocf|Dms. Jedes Document Objekt wäre dann mit einem Content verlinkt.
Donnerstag, Januar 13th, 2011 | by Andreas Bruckner | Posted in SQL 2008 | 1 Comment »
This is a very simple scenario, but is taken from a very complex one.
A Customer may have more than 1 address, some may have none. You only want each customer to appear only once. So what can you do?
SELECT C.Name, A.Address
FROM Customer AS C
OUTER APPLY (SELECT TOP 1 *
FROM Addresses
WHERE CID = C.ID) AS A
Note, that this will never work on SQL CE, but on SQL Server 2005 or 2008! And it’s not part of the ANSI standard!
Dienstag, Oktober 5th, 2010 | by Andreas Bruckner | Posted in Allgemeine Theorien, SQL 2008 | 1 Comment »
SQL Server Management Studio
In some cases the user might install the SQL Server Express Edition, before a “real” SQL Server (Developer Edition).
This can result in a basic version of Management Studio.
Keep in mind, that with SSMSE (e = Express), you cannot manage Analysis Services, Integration Services, or Reporting Services.
The more, you cannot update the full-text catalog by using SSMSE and it does not support scheduling administrative tasks by using SQL Server Agent.
If you installed a Developer Edition of a SQL Server on your system, you also cannot upgrade the basic version of SSMEE. Only possible thing is, to uninstall SQL Express, and do a “Upgrade” with the Developer Edition SQL Setup to the full version.
Easiest way to discover SSMSE: try to connect to a SQL server. If your only choice is “database engine”, that it’s express.
In some cases the user might install the SQL Server Express Edition, before a “real” SQL Server (e.g. Developer Edition).
This can result in a basic version of Management Studio.
Keep in mind, that with SSMSE (e = Express), you cannot manage Analysis Services, Integration Services, or Reporting Services.
The more, you cannot update the full-text catalog by using SSMSE and it does not support scheduling administrative tasks by using SQL Server Agent.
If you later install a Developer Edition of a SQL Server on your system, you also cannot upgrade from the basic version SSMSE. Only possible thing is, to uninstall SQL Express, and do a “Upgrade” with the Developer Edition SQL Setup to the full version SSMS.
Easiest way to discover SSMSE: try to connect to a SQL server: if your only choice is “database engine”, that’s express .
Mittwoch, April 14th, 2010 | by Andreas Bruckner | Posted in SQL 2008 | No Comments »
There are a lot of scripts out there promising to create insert scripts. You pass in the name of the table, and the scripts create an insert statement for each record contained. Only problem they have: the more columns there are, the greater the chance of lines being cut off in the middle.
The only working & free solution I found up to now is called SSMS Tools. You can get it here: LINK.
It integrates into SQL Server Management Studio and offers a couple of functions. The most important: the creation of insert scripts, based on the result of any sql statement.
This is standard functionality in Oracle clients for years now. So MS, please tell me, why this wasn’t implemented into SQL Server 2008?
Montag, März 1st, 2010 | by Andreas Bruckner | Posted in Programmierung Allgemein, SQL 2008 | 1 Comment »
How to use an Update Cursor on MS SQL Server.
Requirements: If the update-table does not have a Primary Key, the cursor is read-only. So I advise to create at least a temporary Primary Key, and delete it afterwards.
Usage:
DECLARE curs as CURSOR
FOR SELECT * FROM t_image
FOR UPDATE
OPEN curs
FETCH curs INTO @lastValue
WHILE (@@FETCH_STATUS = 0) BEGIN
UPDATE [t_image]
SET [CALC_VALUE] = @lastValue
WHERE current of curs
FETCH curs INTO @lastValue
END
CLOSE calc
DEALLOCATE calc
if you replace “WHERE current of curs” by any “WHERE x = y” statement, it would decrease performance dramtically.
During a test with 80000 records, execution time without update cursor takes 20 minutes. Using an update cursor speeds up to a total time of 20 seconds!