Wednesday, March 28, 2012
How Can I recover master database from master's backup?
database from master's backup, but the system show me the
next message RESTORE DATABASE must be in single user mode
when trying to restore the master database.
It's very important to me get information about the
aplication's users but I can't do that.
The system don't permit to put in single user mode to
master then I don't no what to do for resolving this.
Somebody Help me ?
Thanks LorenaSee my other post. No need to re-post.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Lorena" <anonymous@.discussions.microsoft.com> wrote in message
news:bba401c40dea$4e4130a0$a001280a@.phx.gbl...
> I did a new instalation, and I want to recover master
> database from master's backup, but the system show me the
> next message RESTORE DATABASE must be in single user mode
> when trying to restore the master database.
> It's very important to me get information about the
> aplication's users but I can't do that.
> The system don't permit to put in single user mode to
> master then I don't no what to do for resolving this.
> Somebody Help me ?
> Thanks Lorena
>sql
Friday, March 23, 2012
How can I open an OS text file inside one Stored Procedure
I have one Operating System text file in some directory in UNIX environment . How can I open this file inside one Stored Procedure.
Thanks in advance.
DillipHello,
to open flat files in the OS use the package SYS.UTL_FILE. You can use the functions/procedures fopen, get_line and fclose to access the datas in the ff.
You get direct access to the file you must enter the path of the file in your initial parameter. Otherwise Oracle can not read or write the file.
The parameter is UTL_FILE_DIR.
Here is a short example:
declare
fptr utl_file.file_type;
buff varchar2(2048);
line_no number(10):=0;
loc_no integer;
begin
fptr:=utl_file.fopen('C:\Oracle\admin\PENT\udump', 'ORA00324.TRC','R');
utl_file.get_line(fptr,buff);
utl_file.fclose(fptr);
exception
when no_data_found then
utl_file.fclose(fptr);
dbms_output.put_line('Number of lines parsed ='||line_no);
when utl_file.invalid_path then
dbms_output.put_line('invalid path');
raise_application_error(-20100,'file error');
when utl_file.invalid_mode then
dbms_output.put_line('invalid_mode');
raise_application_error(-20100,'file error');
when utl_file.invalid_filehandle then
dbms_output.put_line('invalid_filehandle');
raise_application_error(-20100,'file error');
when utl_file.invalid_operation then
dbms_output.put_line('invalid_operation');
raise_application_error(-20100,'file error');
when utl_file.read_error then
dbms_output.put_line('read_error');
raise_application_error(-20100,'file error');
when utl_file.write_error then
dbms_output.put_line('write_error');
raise_application_error(-20100,'file error');
when utl_file.internal_error then
dbms_output.put_line('internal_error');
raise_application_error(-20100,'file error');
when others then
dbms_output.put_line('un-handled');
raise_application_error(-20100,'file error');
end;
Hope that helps ?
Regards
Manfred Peter
(Alligator Company)
http://www.alligatorsql.com
Monday, March 19, 2012
How can i lock a record
hi all iam working on a ticketing application i want to avoid two users to book the same ticket the requirement is as follows
1. the system should show all the available tickets which is not yet booked
2.when two users book the ticket at the same time time it should not allow the two persons to update at the same tme
the main aim is to avoid data concurency
how can i get this done
Use a flag or the best is to use time-stamps?
|||Hi,
From your description, it seems that your problem is related to SQL concurrency issue.
Suppose each ticket is saved in your data table. For your first requirement, it can be achieved by using a flag which indicates if the ticket has been booked or not.
For your second requirement, since ADO.NET uses Optimistic Concurrency. Then locks are set and held only while the database is being accessed. The locks prevent other users from attempting to update records at the same instant. The data is always available except for the exact moment that an update is taking place.
In Optimistic Concurrency, there are two general ways to determine if changes have occurred: the version approach (true version numbers or date-time stamps) and the saving all values approach.
i.e. For Version Number approach, the record to be updated must have a column that contains a date-time stamp or version number. The date-time stamp or a version number is saved on the client when the record is read. This value is then made part of the update.
For more information, seehttp://msdn2.microsoft.com/en-us/library/cs6hb8k4(VS.71).aspx
Thanks!
Friday, March 9, 2012
How can I improve my SQL query
Hi,
I have this SQL query that can take too long time, up to 1 minute if table contains over 1 million rows. And if the system is very active while executing this query it can cause more delays I guess.
select
distinct 'CONV 1' as Conveyour,
info as Error,
(select top 1 substring(timecreated, 0, 7) from log b where a.info = b.info order by timecreated asc) as Date,
(select count(*) from log b where b.info = a.info) as 'Times occured'
from log a where loggroup = 'CSCNV' and logtype = 4
The table name is LOG, and I retrieve 4 columns: Conveyour, Error, Date and Times occured. The point of the subqueries is to count all distinct post and to retrieve the date of the first time the pst was logged. Also, a first and last date could be specified but is left out here.
Does anyone knows how I can improve this SQL query?
Best /M
Try to avoid the sub-query, The following query may tune your query performance for some extent,
Code Snippet
select distinct
'conv 1' as conveyour,
info as error,
data.date,
data.[times occured]
from log a
join (select info, substring(min(timecreated),0,7) as date, count(*) as [times occured] from log b)
as data on a.info = data.info
where
loggroup = 'cscnv'
and logtype = 4
|||Just wrote this quickly, may or may not work.
Code Snippet
SELECT 'CONV 1' AS [Conveyour]
,info AS [Error]
,MAX(substring(timecreated, 0, 7)) AS [Date]
,COUNT(*) AS [Times occured]
FROM log
WHERE loggroup = 'CSCNV'
AND logtype = 4
GROUP
BY info
I am not sure, as per the Moorstream query the where conditions is not controling the timecreated (date) & count.
Its upto Moorstream to choose..
Ah, I see what you mean, forgot about that bit
Would be interesteing to hear the requirement behind that one.
|||Thank you for your answers, now I have to test these queries and measure execution times
Best,
/M
How can I improve my SQL query
Hi,
I have this SQL query that can take too long time, up to 1 minute if table contains over 1 million rows. And if the system is very active while executing this query it can cause more delays I guess.
select
distinct 'CONV 1' as Conveyour,
info as Error,
(select top 1 substring(timecreated, 0, 7) from log b where a.info = b.info order by timecreated asc) as Date,
(select count(*) from log b where b.info = a.info) as 'Times occured'
from log a where loggroup = 'CSCNV' and logtype = 4
The table name is LOG, and I retrieve 4 columns: Conveyour, Error, Date and Times occured. The point of the subqueries is to count all distinct post and to retrieve the date of the first time the pst was logged. Also, a first and last date could be specified but is left out here.
Does anyone knows how I can improve this SQL query?
Best /M
Try to avoid the sub-query, The following query may tune your query performance for some extent,
Code Snippet
select distinct
'conv 1' as conveyour,
info as error,
data.date,
data.[times occured]
from log a
join (select info, substring(min(timecreated),0,7) as date, count(*) as [times occured] from log b)
as data on a.info = data.info
where
loggroup = 'cscnv'
and logtype = 4
|||Just wrote this quickly, may or may not work.
Code Snippet
SELECT 'CONV 1' AS [Conveyour]
,info AS [Error]
,MAX(substring(timecreated, 0, 7)) AS [Date]
,COUNT(*) AS [Times occured]
FROM log
WHERE loggroup = 'CSCNV'
AND logtype = 4
GROUP
BY info
I am not sure, as per the Moorstream query the where conditions is not controling the timecreated (date) & count.
Its upto Moorstream to choose..
Ah, I see what you mean, forgot about that bit
Would be interesteing to hear the requirement behind that one.
|||Thank you for your answers, now I have to test these queries and measure execution times
Best,
/M
Wednesday, March 7, 2012
How can I hide mssql server system database?
Dear All,
I m using mssql server 2005, when i create a user account for mssql and then use this account to login via management studio. It will show all the system databases and other client databases. How can i hide those databases and allow the client to see their own databases.
Regards,
Ricky
You can hide all databases (other than system databases) by revoking VIEW ANY DATABASE permission from public server role. But you cannot tweak Management Studio to only show certain databases.
Thanks
Laurentiu
Hi Laurentiu
Could you tell me the basic steps (sql statements ) that can allow the clients only its related databases. Because i use a sa account to run "DENY VIEW ANY DEFINITION TO public", the result is incorrect.
Regards,
Ricky
|||Hello,
In order to see who all have access to 'View Any Database' Permission, you can use the following query
SELECT l.name as grantee_name, p.state_desc, p.permission_name
FROM sys.server_permissions AS p JOIN sys.server_principals AS l
ON p.grantee_principal_id = l.principal_id
WHERE permission_name = 'VIEW ANY DATABASE' ;
and to DENY access to public you can use the following syntax
DENY VIEW ANY DATABASE TO PUBLIC
The problem is that what are the related databases for a client is not an easy to answer question: whether a user can or cannot access the database cannot be determined without accessing the database. Testing the user access for all databases will not be efficient if you have hundreds of databases.
If you want to filter databases within SSMS, I don't think there is a way to do that, but the Tools forum is a more appropriate place to get guidance on this issue.
If you want to create your own view that the client can query to see the databases that he has access, you can filter sys.databases using has_dbaccess:
select name from sys.databases where has_dbaccess(name) = 1
Thanks
Laurentiu
I have the opposite problem. When using SSMS on the server itself, I cannot see the system databases tree at all. I tet only "Database Snapshots" and my own database.
However, when accessing this server over a VPN connection, I can see and access the system databases.
I am a Sysadmin and would expect to be able to see everything.
And since the server is running Windows Authentication only, I would expect that my credential are the same, no matter where I login from.
My first guess is that I inadvertantly hid the System Database tree in SSMS, but I see no way to do/undo anything remotely like that.
Per your comment, I remain confused as to how to make them visible. Note that the databases are listed in various dialogs where one would normally select a database (Maint Wizard, for example).
"You can hide all databases (other than system databases) by revoking VIEW ANY DATABASE permission from public server role. But you cannot tweak Management Studio to only show certain databases.
Thanks
Laurentiu"
Can you see the database entries when you query sys.databases? If the catalogs show you the correct information, but SSMS does not, then the issue should be pursued on the Tools forum.
Thanks
Laurentiu
|||Yes, I can see master, tempdb, model and msdb via "select * from sys.databases".
Will re-post in the Tools forum, thanks.
How can I hide mssql server system database?
Dear All,
I m using mssql server 2005, when i create a user account for mssql and then use this account to login via management studio. It will show all the system databases and other client databases. How can i hide those databases and allow the client to see their own databases.
Regards,
Ricky
You can hide all databases (other than system databases) by revoking VIEW ANY DATABASE permission from public server role. But you cannot tweak Management Studio to only show certain databases.
Thanks
Laurentiu
Hi Laurentiu
Could you tell me the basic steps (sql statements ) that can allow the clients only its related databases. Because i use a sa account to run "DENY VIEW ANY DEFINITION TO public", the result is incorrect.
Regards,
Ricky
|||Hello,
In order to see who all have access to 'View Any Database' Permission, you can use the following query
SELECT l.name as grantee_name, p.state_desc, p.permission_name
FROM sys.server_permissions AS p JOIN sys.server_principals AS l
ON p.grantee_principal_id = l.principal_id
WHERE permission_name = 'VIEW ANY DATABASE' ;
and to DENY access to public you can use the following syntax
DENY VIEW ANY DATABASE TO PUBLIC
The problem is that what are the related databases for a client is not an easy to answer question: whether a user can or cannot access the database cannot be determined without accessing the database. Testing the user access for all databases will not be efficient if you have hundreds of databases.
If you want to filter databases within SSMS, I don't think there is a way to do that, but the Tools forum is a more appropriate place to get guidance on this issue.
If you want to create your own view that the client can query to see the databases that he has access, you can filter sys.databases using has_dbaccess:
select name from sys.databases where has_dbaccess(name) = 1
Thanks
Laurentiu
How can I hide mssql server system database?
Dear All,
I m using mssql server 2005, when i create a user account for mssql and then use this account to login via management studio. It will show all the system databases and other client databases. How can i hide those databases and allow the client to see their own databases.
Regards,
Ricky
You can hide all databases (other than system databases) by revoking VIEW ANY DATABASE permission from public server role. But you cannot tweak Management Studio to only show certain databases.
Thanks
Laurentiu
Hi Laurentiu
Could you tell me the basic steps (sql statements ) that can allow the clients only its related databases. Because i use a sa account to run "DENY VIEW ANY DEFINITION TO public", the result is incorrect.
Regards,
Ricky
|||Hello,
In order to see who all have access to 'View Any Database' Permission, you can use the following query
SELECT l.nameas grantee_name, p.state_desc, p.permission_name
FROMsys.server_permissionsAS p JOINsys.server_principalsAS l
ON p.grantee_principal_id = l.principal_id
WHERE permission_name ='VIEW ANY DATABASE';
and to DENY access to public you can use the following syntax
DENY VIEW ANY DATABASE TO PUBLIC
The problem is that what are the related databases for a client is not an easy to answer question: whether a user can or cannot access the database cannot be determined without accessing the database. Testing the user access for all databases will not be efficient if you have hundreds of databases.
If you want to filter databases within SSMS, I don't think there is a way to do that, but the Tools forum is a more appropriate place to get guidance on this issue.
If you want to create your own view that the client can query to see the databases that he has access, you can filter sys.databases using has_dbaccess:
select name from sys.databases where has_dbaccess(name) = 1
Thanks
Laurentiu
I have the opposite problem. When using SSMS on the server itself, I cannot see the system databases tree at all. I tet only "Database Snapshots" and my own database.
However, when accessing this server over a VPN connection, I can see and access the system databases.
I am a Sysadmin and would expect to be able to see everything.
And since the server is running Windows Authentication only, I would expect that my credential are the same, no matter where I login from.
My first guess is that I inadvertantly hid the System Database tree in SSMS, but I see no way to do/undo anything remotely like that.
Per your comment, I remain confused as to how to make them visible. Note that the databases are listed in various dialogs where one would normally select a database (Maint Wizard, for example).
"You can hide all databases (other than system databases) by revoking VIEW ANY DATABASE permission from public server role. But you cannot tweak Management Studio to only show certain databases.
Thanks
Laurentiu"
Can you see the database entries when you query sys.databases? If the catalogs show you the correct information, but SSMS does not, then the issue should be pursued on the Tools forum.
Thanks
Laurentiu
|||Yes, I can see master, tempdb, model and msdb via "select * from sys.databases".
Will re-post in the Tools forum, thanks.
Monday, February 27, 2012
How can I get the table schema using Entreprise Library DAAB ?
i'm using the DAAB (Enterprise Library) to access the data in my system. But I need to use the schema from the tables i'm reading....
when I was using the default DataAdapter, I have used the FillSchema() method, but now, when I use de DAAB to fill de data, I couldn't get the primary keys columns, unique columns neither autoincrement columns...
This is the code that i'm using to get the data with DAAB:
===========================
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper cmd = db.GetSqlStringCommandWrapper("SELECT * FROM Customer");
ds = db.ExecuteDataSet(cmd);
===========================
But this code don't return the schema from the "Customer" table.
Do you have any tip to do it?
thanks people
Andr
Since this is not a Data Mining question, can you try posting to one of these forums?:
.NET Framework Data Access and Storage (http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=45)
SQL Server Data Access (http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=87)
Raman Iyer
SQL Server Data Mining
http://www.sqlserverdatamining.com
Sunday, February 19, 2012
How can I get a table reference knowing his name inside a system f
DBCC CHECKIDENT( ) inside a stored procedure which takes as an input
parameter a @.TableName varchar variable represanting the table's name.
DBCC CHECKIDENT( ) requires as input the table object, while I have the
table string name.
Is there any way that I can get the table object using its string name
inside the DBCC CHECKIDENT() function ?
example
Create procedure procName (@.TableName varchar)
begin
.......
DBCC CHECKIDENT( theTableObject , RESEED, 100)
......
end;Aigiris, Try using the OBJECT_ID function. From the BOL below. - RLF
OBJECT_ID
Returns the database object identification number.
Syntax
OBJECT_ID ( 'object' )
"Argiris Petromelidis" <Argiris Petromelidis@.discussions.microsoft.com>
wrote in message news:AC4CE899-E310-47C3-9101-B12779C2FDA8@.microsoft.com...
>I want to call the system function
> DBCC CHECKIDENT( ) inside a stored procedure which takes as an input
> parameter a @.TableName varchar variable represanting the table's name.
> DBCC CHECKIDENT( ) requires as input the table object, while I have the
> table string name.
> Is there any way that I can get the table object using its string name
> inside the DBCC CHECKIDENT() function ?
> example
> Create procedure procName (@.TableName varchar)
> begin
> ........
> DBCC CHECKIDENT( theTableObject , RESEED, 100)
> ......
> end;|||Hi
You may want to try using dynamic SQL e.g.
CREATE PROCEDURE MyCheck ( @.objectname sysname )
AS
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(@.objectname)
AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
AND EXISTS ( SELECT * FROM dbo.syscolumns WHERE id = OBJECT_ID(@.objectname)
AND COLUMNPROPERTY(id,name,'IsIdentity') = 1)
BEGIN
DECLARE @.cmd varchar(8000)
SET @.cmd = 'DBCC CHECKIDENT( ''' + QUOTENAME(@.objectname) + ''', RESEED,
100)'
EXEC (@.cmd)
END
John
"Argiris Petromelidis" wrote:
> I want to call the system function
> DBCC CHECKIDENT( ) inside a stored procedure which takes as an input
> parameter a @.TableName varchar variable represanting the table's name.
> DBCC CHECKIDENT( ) requires as input the table object, while I have the
> table string name.
> Is there any way that I can get the table object using its string name
> inside the DBCC CHECKIDENT() function ?
> example
> Create procedure procName (@.TableName varchar)
> begin
> ........
> DBCC CHECKIDENT( theTableObject , RESEED, 100)
> ......
> end;