| Thomas 的个人资料Blogs日志列表 | 帮助 |
|
3月8日 Database MirroringWhat is mirroring?
Mirroring constantly synchronizes the transaction log of a mirror server with the transaction log of a principal server. The synchronization can be either synchronal to enable high availability, or asynchronal to enable high performance. If set to high availability, a witness server is required. this can be either the principal server itself, or a 3rd server. If a 3rd server is chosen, this ensures more security in case of a failure. To configure mirroring, the mirror server must restore a backup of the principal with NORECOVERY mode. Thus you cannot access the mirror database directly, since it remains in recovery mode. But you can create a snapshot of the mirror to read data. Also, the database must set to full recovery mode. (Note: if you want to have a full working copy of a database, then log shipping or replication is your choice over mirroring) Mirroring requires endpoints (TCP or HTTP) for the principal, the witness and the mirror server. The endpoints are configured automatically, when you create mirroring in the properties options of the database. The main purpose for mirroring however is to have a high available backup in case of an error of the principal server. In High Availability mode, a failover is automatically performed to the mirror, when a failure occurs on the principal. Otherwise you need to launch a failover manually: ALTER DATABASE <mirror_database> SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS 3月7日 SQL Server Management Studio: Copy DatabaseWhen you right click any Database in the SSMS, you can access the Copy Database tool: This feature easily allows you to copy or move a database from one server to another or within one server. But before you can do this you need to ensure the following conditions:
After the prerequisites are confirmed, you can launch the Copy Database wizard. There are currently two ways to copy or move the database:
Use the SQL Management Object Method
1) is significantly faster but requires a share on the target server and a configured Integration Services Proxy Account on the target server. So the easiest way to copy the source is method 2). After some view steps in the wizard, you reach the Select Server Objects page where Logins are preselected: Copying the Logins is not necassarily required unless you have granted some rights to specific logins, so in some cases you can remove the Logins from the Selected related objects list. in some cases.
Use the detach and attach method
If you decide to use this method to copy or move a database, before you can archive this, you need to create a Credential and a Proxy for the SSIS Package Execution in the SQL Server Agent: To create a credential that will be later associated to the proxy open Server/Security/Credential and right click to open the popup menu where you select New Credential: The New Credential Dialog is self explanatory so just configure the required values. Now you can create a Proxy:
In the dialog select a proxy name of your choice and as Credential name select the previously created credential. Select at least “SQL Server Integration Services Package” and that’s it: 3月3日 Contains with the Entity Framework.Sometimes you need to get a result set for a field that contains any value from an array. from var c in data where array.Contains(c.field) select c; which creates a T-SQL that looks like that: select * from data where data.field in (1,2,3,...) Unfortunately, this would produce an error with EF, since Contains is currently not implemented with .NET 3.5SP1. private void button2_Click(object sender, RoutedEventArgs e) Intersection with Linq2SQLImagine you have a data table that is specified as followed:
CREATE TABLE MyTable
ArticleId int NOT NULL,
CategoryId int NOT NULL and you want to return all article ids that interesect with an array of Category Id's using LINQ2SQL.
Here is a solution:
int[] categoryIds = new int[] {29,5201,4}; IQueryable<ObjectNodeView> result = context.MyTable; // make a select for the first category: int firstCategory = categoryIds.First(); result = from a in result where a.CategoryId == firstCategory select a; // now intersect all other categories using a inner join: foreach(int categoryId in categoryIds.Skip(1)) { result = from a in result join a2 in context.MyTable on a.ArticleId equals a2.ArticleId where a2.CategoryId == categoryId select a; } 3月2日 Urban legends - Truth or Myth?Select with EF is always slower than with Linq2SQLThis is only true when you leave the default value of ObjectQuery.MergeOption or set it to any other value but MergeOption.NoTracking. However, if you do set this value to MergeOption.NoTracking, a select will be 3 times faster than with LINQ2SQL. The following table compares various scenarios:
So what you see here is that EDM is the fastest access after DataReader, but also the slowest if tracking is (by default) enabled. Depending on what you do, you might consider to disable Tracking for faster read access, but with the possibility of redundant data in memory.
Linq2Sql supports MS SQL onlyThis is not really true! Though there is currently only one IQueryProvider for MS SQL, but who prevents other SQL Provider to implement their own IQueryProvider? For instance, Oracle offers native DbConnection, DbCommand and DbReader, why not a QueryProvider? EDM does not support UDF (User defined Functions)Unfortunately, as with .NET 3.5 SP1 this is true. Though you can currently describe a function with <Function Name="MyUDF" Aggregate="false" BuiltIn="false" NiladicFunction="false" IsComposable="true" ParameterTypeSemantics="AllowImplicitConversion" Schema="dbo" ReturnType="nvarchar(max)"> <Parameter Name="title" Type="nvarchar(max)" Mode="In" /> </Function> where it differs from a stored procedure by IsComposable set to true instead of false, there is currently no support for it. Usage of UDF with EF is announced to be available with .NET 4.0
Linq2SQL can do everything that EF can do and moreNo. There are some features that is currently not possible with EF, but there are also features in EF that is not available with Linq2SQL.
|
|
|