Wednesday, May 7, 2014

How to execute generated script(.sql file) with schema and data in SQL Server 2008

SQL Server offers 2 command prompt features that can se used for executing large queries - osql (will be removed in future), and sqlcmd
osql is located in the Tools\Binn subfolder. To execute a SQL script:
  1. Start the Command Prompt
  2. Navigate to the folder where the osql utility is located
  3. Run the command in the following format:
    osql –H <workstation name> -S <server_name[\instance_name]> -U <user login ID> -P <login password> –i <full path to script>
To execute the large.sql file located in the D:\test, against the Central database on the SQL Server instance Dell\SQL2012, as an sa with the 'sqladmin' password, run the following command:
osql -H Dell -S Dell\SQL2012 -i D:\test\large.sql -U sa -P sqladmin
The sqlcmd command line utility is also located in the SQL Server’s Tools\Binn sub-directory. To execute a SQL script:
  1. Start the Command Prompt
  2. Navigate to the folder where the sqlcmd utility is located
  3. Run a command in the following format:
    sqlcmd –S <server name> -d <database name> -i <full path to script> -U <user login ID> –P <login password>
To execute the same as above, run the following command:
sqlcmd -S Dell\SQL2012 -d Central -i D:\test\large.sql -U sa P sqladmin

Friday, April 11, 2014

Difference between .NET Framework 4.5 and .NET Framework 4.0

.NET Framework 4.0 support fallowing features:-

Web.config File Refactoring
Extensible Output Caching
Auto-Start Web Applications
Permanently Redirecting a Page
Shrinking Session State
Expanding the Range of Allowable URLs
Extensible Request Validation
Object Caching and Object Caching Extensibility
Extensible HTML, URL, and HTTP Header Encoding
Performance Monitoring for Individual Applications in a Single Worker Process
Multi-Targeting .... etc

.NET Framework 4.5 support fallowing improvement features:-

Asynchronously Reading and Writing HTTP Requests and Responses
Improvements to HttpRequest handling
Asynchronously flushing a response
Support for await and Task-Based Asynchronous Modules and Handlers

 What is new in .NET Framework 4.5 

.NET Framework 4.5 Support for Windows Runtime
.NET Framework 4.5 Support for Metro Style Applications
.NET Framework 4.5 Support for Async Programming
 Garbage Collector Improvements
.NET Framework 4.5 is Faster ASP.NET Startup
.NET Framework 4.5 Support Better Data Access
.NET Framework 4.5 Support WebSockets                         
 Workflow Support - BCL Support

Tuesday, April 1, 2014

connect to an MDF database file asp.net

con.ConnectionString = @"Data Source=.\SQLEXPRESS;
                          AttachDbFilename=c:\folder\SampleDatabase.mdf;
                          Integrated Security=True;
                          Connect Timeout=30;
                          User Instance=True";

Get table name and its SCHEMA NAME from database sql server

SELECT Distinct TABLE_NAME,SCHEMA_NAME() FROM information_schema.TABLES

C# / SQL Get all Stored Procedures and their Code

SELECT    sysobjects.name, syscomments.text
FROM    sysobjects
JOIN    syscomments
    ON    sysobjects.id = syscomments.id
WHERE    xtype='p'

Wednesday, March 12, 2014

OLE DB provider “Microsoft.ACE.OLEDB.12.0” for linked server “(null)”

  1. On 64-bit servers and boxes, you need to first UNINSTALL all 32-bit Microsoft Office applications and instances (Access 2007 install, Office 10 32-bit, etc.). If you dont, you cannot install the new 64-bit Microsoft Access Database Engine 2010 Redistributable components. Yes, its a headache but the only way I found to install the new replacements for the JET engine components that need to run on 64-bit machines.
  2. Download and install the new component from Microsoft:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c06b8369-60dd-4b64-a44b-84b371ede16d&displaylang=en
    • This will install the access and other engines you need to set up linked servers, OPENROWSET excel files, etc.
  3. Open up SQL Server and run the following:
    sp_configure 'show advanced options', 1;
    GO
    RECONFIGURE;
    GO
    sp_configure 'Ad Hoc Distributed Queries', 1;
    GO
    RECONFIGURE;
    GO
    EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
    GO
    EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
    GO
    • This sets the parameters needed to access and run queries related to the components. Address ‘null
  4. Now, if you are running OPENROWSET calls you need to abandon calls ,made using the old JET parameters and use the new calls as follows:
    (*Example, importing an EXCEL file directly into SQL):
    DONT DO THIS….
    SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;HDR=YES;Database=c:\PATH_TO_YOUR_EXCEL_FILE.xls','select * from [sheet1$]')
    
    USE THIS INSTEAD
    SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=c:\PATH_TO_YOUR_EXCEL_FILE.xls','select * from [sheet1$]')
    
    *At this point resolved two SQL issues and ran perfectly
  5. Now for the fun part…..find all your Office Disks and reinstall Office and/or applications needed back onto the machine. You can install the 64- bit version of Office 10 by going onto the disk and going into the 64-bit folder and running it but beware as in some cases some third party apps dont interface yet with that version of Office.

Friday, March 7, 2014

How to detect if a string contains special characters or number

DECLARE @MyString VARCHAR(100)
SET @MyString = 'adgkjb$'

IF (@MyString LIKE '%[^a-zA-Z0-9]%')
    PRINT 'Contains "special" characters'
ELSE
    PRINT 'Does not contain "special" characters'


for number
DECLARE @MyString VARCHAR(100)
SET @MyString = 'adgkjb$'

IF (@MyString LIKE '%[^0-9]%')
    PRINT 'not Contains "number" characters'
ELSE
    PRINT 'contain "number" characters'

Opps Part 1 : Abstraction

  Abstraction in C# is a fundamental concept of object-oriented programming (OOP) that allows developers t...