نکات کاربردی

طبقه بندی موضوعی

آخرین مطالب

یکی از دلایل خطا میتواند در اختلاف ستون CheckpointLSN در فول بکاپ با ستون DatabaseBackupLSN در دیفرنشیال بکاپ باشد.


بایستی مقدار CheckpointLSN در فول بکاپ با ستون DatabaseBackupLSN در دیفرنشیال بکاپ برابر باشد.


اگر این دو عدد مغایر هستند بمعنای این است که فول بکاپ دیگری انجام شده.


دستور نمایش فیلدهای فوق بشکل زیر است:

RESTORE HEADERONLY   FROM DISK = N'C:\AdventureWorks-FullBackup.bak'; 



Full&Diff


Backup chain

behrad nasehi
۲۴ دی ۹۶ ، ۱۶:۲۷ موافقین ۰ مخالفین ۰ ۱ نظر

برای رفع مشکل حروف فارسی در خروجی CSV بایستی خطوط شماره 1 و 2 و3 را اضافه کنید:


Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + date);
Response.ContentType = "text/csv";
1-Response.Charset = Encoding.Unicode.ToString();
2-Response.ContentEncoding = System.Text.Encoding.Unicode;

/*
save utf-8 with BOM
برای ذخیره درست فارسی بایستی کد زیر فراخوانی شود
GetPreamble
*/
3-Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
foreach (DataRow r in ds.Tables[0].Rows)
{
Response.Write(r[0]);
Response.Write("\r\n");
}
Response.End();

https://stackoverflow.com/questions/1679656/asp-net-excel-export-encoding-problem
behrad nasehi
۰۳ دی ۹۶ ، ۱۶:۱۶ موافقین ۰ مخالفین ۰ ۰ نظر

You need CROSS APPLY not join.

The definition of table expressions involved in joins must be stable. I.e. They can't be correlated such that the table expression means something different dependant on the value of a row in another table.

select f.ID, f.Desc, u.Field1, u.Field2
from Foo f 
Cross apply ut_FooFunc(f.ID, 1) u
where f.SomeCriterion = ...

How to join a table with a table valued function?


behrad nasehi
۱۱ مهر ۹۶ ، ۱۰:۴۹ موافقین ۰ مخالفین ۰ ۰ نظر

If you're like me, you probably have a significant number of servers you access on a regular basis, which means every time you start up SQL Server Management Studio (SSMS) you have to log in to each server typing in user names and passwords and connecting one at a time. I find this very obnoxious and annoying.

Thankfully, SQL Server Management Studio allows you to save connections to various servers via Registered Servers, which can include Database Engines, Reporting Services, Integration Services, and Analysis Services. Registered servers allow you to easily check if a server is running, create groups of servers, use user-friendly names for your servers, and import/export your registered server groups.

To view and add a registered server, start up SSMS go to View > Registered Servers. Then in the Registered Servers pane, right-click Local Server Groups and click New Server Registration.

New Registered Server

Then just enter the server name, select the authentication, key in the User name and Password if necessary, and check Remember password.

Now each time you start up SSMS, your registered servers will be viewable in the Registered Servers pane. Simply double-click the server you wish to navigate and that server will be opened within the Object Explorer.


Save Frequently Used Connections in SQL Server Management Studio

behrad nasehi
۰۹ شهریور ۹۶ ، ۱۱:۱۹ موافقین ۰ مخالفین ۰ ۰ نظر
declare @nuke_spid int

select  @nuke_spid = session_id
from    sys.dm_exec_requests r
outer apply sys.fn_get_sql(r.sql_handle) s
where   s.text like '%sanad_insert r%'

بعد از مقدار کردن متغیر nuke_spid@ با دستور kill اقدام به توقف نمائید.

مثلا اگر مقدار متغیر فوق 65 شد با دستور

kill 65


Stopping long running stored procedure from script

behrad nasehi
۲۰ خرداد ۹۶ ، ۱۴:۱۵ موافقین ۰ مخالفین ۰ ۰ نظر
DECLARE @childID INT 
SET @childID  = 1 --chield to search

;WITH RCTE AS
(
    SELECT *, 1 AS Lvl FROM RelationHierarchy 
    WHERE ChildID = @childID

    UNION ALL

    SELECT rh.*, Lvl+1 AS Lvl FROM dbo.RelationHierarchy rh
    INNER JOIN RCTE rc ON rh.CHildId = rc.ParentId
)
SELECT TOP 1 id, Name
FROM RCTE r
inner JOIN dbo.Person p ON p.id = r.ParentId
ORDER BY lvl DESC
behrad nasehi
۱۵ خرداد ۹۶ ، ۱۶:۲۸ موافقین ۰ مخالفین ۰ ۱ نظر
1-Setting Up a Local Git Repository

create a local Git repository

  1. Open the project you want to store in a repository.
  2. On the main menu, choose VCS | Import into Version Control | Create Git Repository.
  3. In the dialog that opens, specify the directory where you want to create a new Git repository.
  4. Put the required files under Git version control. The files appear in the Local Changes tab of the Version Control tool window, under the Default changelist


2-Adding Files to a Local Git Repository

View | Tool Windows | Version Control - Local Changes
Alt+9

Basics

After a Git repository for a project is initialized, you need to add the project data to it.


Adding all currently unversioned files to Git control

  1. Switch to the Version Control tool window and switch to the Local Changes tab. tool window.
  2. Expand the Unversioned Files node and choose Add to VCS from the context menu or pressCtrl+Alt+A.

Adding specific files to a local Git repository

Do one of the following:

  • Switch to the Version Control tool window and switch to the Local Changes tab. Expand the Unversioned Files node, and select the files to be added. From the context menu, chooseAdd to VCS, or press Ctrl+Alt+A.
  • Switch to the Project tool window and select the files to be added. From the context menu, choose Git | Add or pressCtrl+Alt+A.


***

Adding Files to Version Control

If a new file is created with IntelliJ IDEA in a directory that is already under version control, it automatically adds to the active changelist with the status Added. All you have to do, is to commit this change.

IntelliJ IDEA's behavior on adding files is configurable in the General Settings tab of the Version Control dialog.

If a new file is created outside of IntelliJ IDEA, or silent adding is disabled, you have to explicitly add it to the version control.

Another approach is VCS-specific. You can import an entire directory to your repository, provided that you have the corresponding access rights. This action is helpful for putting a whole project under version control.

To explicitly add a file to version control

  1. Select file in the Project tool window.
  2. On the main Version Control menu or on the context menu of the selected file, choose <VCS> | Add.

    Alternatively, use the Version Control tool window. Select the desired files in the Unversioned files changelist in the Local Changes tab, and choose Add to VCS on the context menu, or just drag it to the target changelist.

    img
  3. Select the added file in the changelist and check in (commit) changes.

behrad nasehi
۰۵ آبان ۹۵ ، ۲۰:۰۵ موافقین ۰ مخالفین ۰ ۰ نظر

This tutorial will teach you on creating web application using maven in IntelliJ. This assumes that you have maven installed in your local machine. If not, check this tutorial of installing maven on windows.

1. Start by creating a new project in IntelliJ

Under new project, on the left side, click Maven. Add your project name and the location of the project to be save. Choose your JDK version, in our case, we use Java 8. You should see something similar below,

new project

Click Next. The GroupId and ArtifactId will be filled by default values based on the project name. Tick in Create from arechetype, and choose org.apache.maven.archetypes:maven-archetype-webapp. Click Next to continue creating the project.
new project 2

After creating the project, you should see your project structure to something similar below,

project structure

By default, when creating a webapp project in maven, it doesn’t include the java folder for the source code. For the sake of simplicity, we will just add a new folder under the main folder named java.

2. Configure pom.xml

Above dependencies section, add properties section containing the jdk.version definition:


1
2
3
<properties>
    <jdk.version>1.8</jdk.version>
</properties>

Under build section, add the maven compiler plugin and jetty plugin. Jetty plugin will be the web app container just like tomcat, jboss, glassfish, etc.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
            <source>${jdk.version}</source>
            <target>${jdk.version}</target>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.10</version>
        <configuration>
            <scanIntervalSeconds>10</scanIntervalSeconds>
            <connectors>
                <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                    <port>8080</port>
                    <maxIdleTime>60000</maxIdleTime>
                </connector>
            </connectors>
            <stopKey>STOP</stopKey>
            <stopPort>8005</stopPort>
        </configuration>
    </plugin>
</plugins>

The final pom.xml should be something similar to this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
    <modelVersion>4.0.0</modelVersion>
    <groupId>SpringMVC4</groupId>
    <artifactId>SpringMVC4</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>SpringMVC4 Maven Webapp</name>
    <url>http://maven.apache.org</url>
 
    <properties>
        <jdk.version>1.8</jdk.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
 
    </dependencies>
    <build>
        <finalName>SpringMVC4</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.10</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <connectors>
                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                            <port>8080</port>
                            <maxIdleTime>60000</maxIdleTime>
                        </connector>
                    </connectors>
                    <stopKey>STOP</stopKey>
                    <stopPort>8005</stopPort>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

3.Deploying/Running the Project

On the right side, open Maven Projects. In case this tab is not visible, you can open this by click the square located at the lower left corner a. Under Maven Projects, open your webapp project, click plugins and double click jetty:run. To debug, right click jetty:run and click debug project. This will deploy your project.

maven jetty

In the console you can see the status of your deployment. Once you see something like Started SelectChannelConnector@0.0.0.0:8080, you can now browse the web at address localhost:8080/ProjectName and you should see the default jsp page.

hello world maven
You can download the source code here.

مرجع

behrad nasehi
۰۵ آبان ۹۵ ، ۱۸:۵۶ موافقین ۰ مخالفین ۰ ۱ نظر
behrad nasehi
۰۳ آبان ۹۵ ، ۲۲:۱۱ موافقین ۰ مخالفین ۰ ۰ نظر

So here is the scenario: you have a stored procedure which inserts new rows to a database table and you want to call it from your .NET code (in my case the application was a BizTalk orchestration using WCF-SQL adapters). You can successfully execute the procedure in SQL Server Management Studio, but when your code calls it, you get an error like this:

INSERT failed because the following SET options have incorrect settings: 'ARITHABORT'

Resolving the error is pretty easy, you add the following line after the BEGIN clause in your stored procedure:

SET ARITHABORT ON; 

Queries failing because of the ARITHABORT setting

behrad nasehi
۲۴ شهریور ۹۵ ، ۰۶:۱۴ موافقین ۰ مخالفین ۰ ۰ نظر