Wednesday, January 23, 2013

simple binding wpf listbox to datatable by code / einfaches binden einer wpf listbox an eine datatable mittels code


xaml: add Listbox and Loaded:
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525"
        Loaded="Window_Loaded">
           


CodeBehind:
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            SqlConnection sqlCon = new SqlConnection("server=192.168.1.231; database=hewmicTest;Trusted_Connection=True");
            sqlCon.Open();
            SqlDataAdapter sqlDa = new SqlDataAdapter("select * from testTable", sqlCon);
            DataTable dt = new DataTable();
            sqlDa.Fill(dt);
            lb.ItemsSource = dt.Rows;
            lb.DisplayMemberPath = "ItemArray[1]";
            sqlCon.Close();
            //MessageBox.Show("ConnState=" + sqlCon.State);
        }

Monday, January 21, 2013

tabellenzugriff mittel sql server audit überwachen


ab sql2008, im ssms unter security (server und database)


USE master ;
GO
-- Create the server audit.
CREATE SERVER AUDIT hewMicSqlServerAuditTest TO APPLICATION_LOG ; -- windows application log
--alternative: TO FILE  (FILEPATH ='c:\temp\' );
GO
-- Enable the server audit.
ALTER SERVER AUDIT hewMicSqlServerAuditTest WITH (STATE = ON) ;
GO
-- Move to the target database.
USE hewmicTest ;
GO
-- Create the database audit specification.
CREATE DATABASE AUDIT SPECIFICATION testSpec FOR SERVER AUDIT hewMicSqlServerAuditTest
ADD (SELECT , INSERT ON dbo.testTable BY dbo )
WITH (STATE = ON) ;
GO