EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'ADSI'
,@useself=N'FALSE',@locallogin=NULL,@rmtuser='{Domain\UserName}',@rmtpassword=''
SELECT *
FROM OPENQUERY( ADSI,
'SELECT Name, SN, ST
FROM ''LDAP://AAM.NET''
WHERE objectCategory = ''Person'' AND
objectClass = ''user''')
Showing posts with label MS SQL 2005-08. Show all posts
Showing posts with label MS SQL 2005-08. Show all posts
Tuesday, July 14, 2009
Friday, May 8, 2009
How to access network file in SQL
How can I access network XML file from SQL server store procedure?
A procedure which is accessing local file "C:\xyzConfig\xyz.xml" as one of the string parameter.
Now my SQL instance is changed to different server but XML location is same.
I tried "\\SERVER100\c$\xyzConfig\xyz.xml" but It won't work.
Error throw as
"....... could not be opened. Operating system error code 5(Access is denied.)."
----------
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/d64c98c7-4fdf-41ba-8413-e606ec668efa
here how I resolve with your help,
1) I have a web application on Server100 with IIS & etc..
2) SQL instance is a cluster on Server400 which doesn’t have IIS & etc..
3) make share folder on Server400, Drive X, then I can access file from SQL as local file. Share with read & write permission for domain users
4) but no IIS on Server400 so, it is not allow me to set Web Sharing folder.
5) So, From web app. i have to set up
6) after all I can access file from both process.
A procedure which is accessing local file "C:\xyzConfig\xyz.xml" as one of the string parameter.
Now my SQL instance is changed to different server but XML location is same.
I tried "\\SERVER100\c$\xyzConfig\xyz.xml" but It won't work.
Error throw as
"....... could not be opened. Operating system error code 5(Access is denied.)."
----------
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/d64c98c7-4fdf-41ba-8413-e606ec668efa
here how I resolve with your help,
1) I have a web application on Server100 with IIS & etc..
2) SQL instance is a cluster on Server400 which doesn’t have IIS & etc..
3) make share folder on Server400, Drive X, then I can access file from SQL as local file. Share with read & write permission for domain users
4) but no IIS on Server400 so, it is not allow me to set Web Sharing folder.
5) So, From web app. i have to set up
Monday, October 13, 2008
MS SQL Server 2008 new features
Data Compression
SQL Server 2008 gives us the ability to compress data and save on disk space. Without getting into many specifics, data in SQL Server can be compressed at the page level. This means that when you compress a table, it actually does it a page at a time. I'd advise you to tread lightly with data compression. You should make sure you do your research and testing before implementing compression in your environment. That said, when disk space is at a premium, you can use this feature to pack more data onto the platters.
Backup Benefits
SQL Server 2008 provides backup compression. With backup compression, you have the savings of file size built right into the native backup.
To use backup compression, you just need to add the WITH COMPRESSION option to a BACKUP DATABASE statement as shown below:
BACKUP DATABASE Adventureworks2008
TO DISK = 'D:\Backup\AdventureWorks.bak'
WITH COMPRESSION
Here's an example of the compression ratio: a backed up 965MB database without compression resulted in a 636MB backup file. Using compression, the same database produced a 147MB backup file.
Learn to Merge
The new MERGE statement in SQL Server 2008 obviates the need for "IF-THEN" logic to decide whether a row needs to be inserted, updated or deleted. MERGE allows you to take care of the logic and the modification all in one shot. What's more, you can compare an entire record set all at once instead of going row by row. Here's a quick example of using MERGE:
MERGE tbl_address AS current_addresses
USING (
SELECT customer_objid = address_label,
addressline1, addressline2, city, region, country, zip
code, is_deleted
FROM @addresses)
AS
source_addresses(address_label, addressline1,
addressline2, city, region, country, zipcode,
is_deleted)
ON
(
current_addresses.address_label = source_address
es.address_label
)
WHEN NOT MATCHED THEN
INSERT (address_label, addressline1, addressline2,
city, region, country, zipcode)
VALUES (source_addresses.address_label,
source_addresses.addressline1,
source_addresses.addressline2,
source_addresses.city, source_addresses.region,
source_addresses.country, source_addresses.zipcode)
WHEN MATCHED AND source_addresses.is_deleted
= 1
THEN DELETE
WHEN MATCHED THEN
UPDATE
SET address_label=source_addresses.address_label,
addressline1=source_addresses.addressline1,
addressline2=source_addresses.addressline2,
city=source_addresses.city, region=source_address
es.region, country=source_addresses.country,zip
code=source_addresses.zipcode
The USING section defines the "new" data, in this case a table variable. The ON section defines the join between the new and existing data. Finally, you have a series of MATCHED statements that do things like insert WHEN NOT MATCHED, update WHEN MATCHED or delete WHEN MATCHED and some other value indicates delete. This is a real time saver, and the syntax is much cleaner that the older alternative of using homegrown logic
SQL Server 2008 gives us the ability to compress data and save on disk space. Without getting into many specifics, data in SQL Server can be compressed at the page level. This means that when you compress a table, it actually does it a page at a time. I'd advise you to tread lightly with data compression. You should make sure you do your research and testing before implementing compression in your environment. That said, when disk space is at a premium, you can use this feature to pack more data onto the platters.
Backup Benefits
SQL Server 2008 provides backup compression. With backup compression, you have the savings of file size built right into the native backup.
To use backup compression, you just need to add the WITH COMPRESSION option to a BACKUP DATABASE statement as shown below:
BACKUP DATABASE Adventureworks2008
TO DISK = 'D:\Backup\AdventureWorks.bak'
WITH COMPRESSION
Here's an example of the compression ratio: a backed up 965MB database without compression resulted in a 636MB backup file. Using compression, the same database produced a 147MB backup file.
Learn to Merge
The new MERGE statement in SQL Server 2008 obviates the need for "IF-THEN" logic to decide whether a row needs to be inserted, updated or deleted. MERGE allows you to take care of the logic and the modification all in one shot. What's more, you can compare an entire record set all at once instead of going row by row. Here's a quick example of using MERGE:
MERGE tbl_address AS current_addresses
USING (
SELECT customer_objid = address_label,
addressline1, addressline2, city, region, country, zip
code, is_deleted
FROM @addresses)
AS
source_addresses(address_label, addressline1,
addressline2, city, region, country, zipcode,
is_deleted)
ON
(
current_addresses.address_label = source_address
es.address_label
)
WHEN NOT MATCHED THEN
INSERT (address_label, addressline1, addressline2,
city, region, country, zipcode)
VALUES (source_addresses.address_label,
source_addresses.addressline1,
source_addresses.addressline2,
source_addresses.city, source_addresses.region,
source_addresses.country, source_addresses.zipcode)
WHEN MATCHED AND source_addresses.is_deleted
= 1
THEN DELETE
WHEN MATCHED THEN
UPDATE
SET address_label=source_addresses.address_label,
addressline1=source_addresses.addressline1,
addressline2=source_addresses.addressline2,
city=source_addresses.city, region=source_address
es.region, country=source_addresses.country,zip
code=source_addresses.zipcode
The USING section defines the "new" data, in this case a table variable. The ON section defines the join between the new and existing data. Finally, you have a series of MATCHED statements that do things like insert WHEN NOT MATCHED, update WHEN MATCHED or delete WHEN MATCHED and some other value indicates delete. This is a real time saver, and the syntax is much cleaner that the older alternative of using homegrown logic
Wednesday, September 24, 2008
Msg 6602, Level 16, State 2, Procedure sp_xml_preparedocument, Line 1
Msg 6602, Level 16, State 2, Procedure sp_xml_preparedocument, Line 1
The error description is 'Whitespace is not allowed at this location.'.
Msg 8179, Level 16, State 5, Procedure XXXXX, Line 45
Could not find prepared statement with handle 15.
sp_xml_removedocument: The value supplied for parameter number 1 is invalid.
Whe you parsing xml document, xml tag string contain invalide character li ",&,use
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3576805&SiteID=1
XmlReaderSettings readerSetttings = new XmlReaderSettings();
readerSetttings.CheckCharacters = false;
best decribe
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1723005&SiteID=1
The error description is 'Whitespace is not allowed at this location.'.
Msg 8179, Level 16, State 5, Procedure XXXXX, Line 45
Could not find prepared statement with handle 15.
sp_xml_removedocument: The value supplied for parameter number 1 is invalid.
Whe you parsing xml document, xml tag string contain invalide character li ",&,use
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3576805&SiteID=1
XmlReaderSettings readerSetttings = new XmlReaderSettings();
readerSetttings.CheckCharacters = false;
best decribe
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1723005&SiteID=1
Tuesday, July 22, 2008
MS SQL (7/2000) database "Suspect Mode" / "Emergency Mode" / "Error 1813
Recovering MSSQL from "Suspect Mode" / "Emergency Mode" / "Error 1813"
For SQL 2000 database some time database goes into suspect mode, when you trying to delete database directly.
sp_configure "Allow updates" , 1
go
update sysdatabases
set status = status & ~ 256
where (name = 'SuspectDatabaseName')
go
sp_configure "Allow updates" , 0
go
* user must be SQL admin user.
it will restore database.
if still not works go for hotfix
click here http://support.microsoft.com/kb/889266
try this http://www.gerixsoft.com/node/24
(good post)
keep in mind
The issues that are fixed by this hotfix package.
The prerequisites for installing the hotfix package.
Whether you must restart your computer after you install the hotfix package.
The files that are contained in the hotfix package।
"Suspect Mode" --> "Emergency Mode"
Open Enterprise Manager,
Right click onto your server node, - an SQL Server Properties dialog will popup,
Enable "Allow modifications to be made directly to the system catalogs" option
Now proceed to the sysdatabases table in the master database, locate your database row and put 32768 into its status column
Restart SQL Server and refresh Enterprise Manager
Open Enterprise Manager - the database will be marked as "Emergency Mode"
These articles explain the trick behind suspect and emergency mode:http://support.microsoft.com/support/kb/articles/Q165/9/18.ASPhttp://www.swynk.com/friends/knight/unmarksuspect.asphttp://support.microsoft.com/support/kb/articles/Q180/5/00.asp
3. "Emergency Mode" --> "Normal Mode"
Now your database is in "emergency mode". Disregard Enterprise Manager does not show tables, views and procedures - use Query Analyzer's Object Browser instead.
"Emergency mode" means database is locked against any modifications, it is readonly forever. There is no way to bring "emergency" database back to normal state. All we can do is copy all data from it into new database.
Create new database (pubz)
Create new DTS package
Use "Copy SQL Objects" task to transfer data from old database to new database (pubs->pubz)
Execute the DTS job & enjoy!
Note that there might be complex dependencies between database objects, so Copy SQL Objects task might not work properly. For example: view A is dependent on view Z; Copy SQL Objects task will try to create view A first, -- that will fail, because view Z does not exist yet.
4. "Error 1813" --> "Suspect Mode"
If you receive "Error 1813", this probably means that you are trying to attach database you have improperly detached, or haven't detached at all. Only successfully detached databases can be successfully attached back.
Create new database using the same name and file location as database that is failing to attach
Stop SQL Server
Copy non-attachable data files over the new ones
Delete log files
Start SQL Server
Open Enterprise Manager - the database will be marked as "suspect"
Once your database is "suspect", use instructions outlined above...
Note that database will be marked "suspect" only if transaction log contained active sections. To illustrate the problem for 100%, run a few inserts against the database before deleting transaction log.
http://www.gerixsoft.com/trackback/24
For SQL 2000 database some time database goes into suspect mode, when you trying to delete database directly.
sp_configure "Allow updates" , 1
go
update sysdatabases
set status = status & ~ 256
where (name = 'SuspectDatabaseName')
go
sp_configure "Allow updates" , 0
go
* user must be SQL admin user.
it will restore database.
if still not works go for hotfix
click here http://support.microsoft.com/kb/889266
try this http://www.gerixsoft.com/node/24
(good post)
keep in mind
The issues that are fixed by this hotfix package.
The prerequisites for installing the hotfix package.
Whether you must restart your computer after you install the hotfix package.
The files that are contained in the hotfix package।
"Suspect Mode" --> "Emergency Mode"
Open Enterprise Manager,
Right click onto your server node, - an SQL Server Properties dialog will popup,
Enable "Allow modifications to be made directly to the system catalogs" option
Now proceed to the sysdatabases table in the master database, locate your database row and put 32768 into its status column
Restart SQL Server and refresh Enterprise Manager
Open Enterprise Manager - the database will be marked as "Emergency Mode"
These articles explain the trick behind suspect and emergency mode:http://support.microsoft.com/support/kb/articles/Q165/9/18.ASPhttp://www.swynk.com/friends/knight/unmarksuspect.asphttp://support.microsoft.com/support/kb/articles/Q180/5/00.asp
3. "Emergency Mode" --> "Normal Mode"
Now your database is in "emergency mode". Disregard Enterprise Manager does not show tables, views and procedures - use Query Analyzer's Object Browser instead.
"Emergency mode" means database is locked against any modifications, it is readonly forever. There is no way to bring "emergency" database back to normal state. All we can do is copy all data from it into new database.
Create new database (pubz)
Create new DTS package
Use "Copy SQL Objects" task to transfer data from old database to new database (pubs->pubz)
Execute the DTS job & enjoy!
Note that there might be complex dependencies between database objects, so Copy SQL Objects task might not work properly. For example: view A is dependent on view Z; Copy SQL Objects task will try to create view A first, -- that will fail, because view Z does not exist yet.
4. "Error 1813" --> "Suspect Mode"
If you receive "Error 1813", this probably means that you are trying to attach database you have improperly detached, or haven't detached at all. Only successfully detached databases can be successfully attached back.
Create new database using the same name and file location as database that is failing to attach
Stop SQL Server
Copy non-attachable data files over the new ones
Delete log files
Start SQL Server
Open Enterprise Manager - the database will be marked as "suspect"
Once your database is "suspect", use instructions outlined above...
Note that database will be marked "suspect" only if transaction log contained active sections. To illustrate the problem for 100%, run a few inserts against the database before deleting transaction log.
http://www.gerixsoft.com/trackback/24
Monday, July 21, 2008
SQL find out two date between intervals
select getdate()
select dateadd("yy",-1,getdate())
dd - day
mm - month
yy - year
-1 - add -1 day/month/year in gurrent date.
select dateadd("yy",-1,getdate())
dd - day
mm - month
yy - year
-1 - add -1 day/month/year in gurrent date.
Subscribe to:
Posts (Atom)