Showing posts with label databases. Show all posts
Showing posts with label databases. Show all posts

Thursday, March 22, 2012

Active/Active or Active/Passive

Hello,
We are going to design our SQL Server databases on either Active/Active or
Active/Passive of Windows 2003 clusters.
Has any one seen real time risk and their real experiences of using
Active/Active clusters?
Thanks, John
The only real issue is when one node dies and its SQL instance(s)
failover to the other node so a single node has multiple instances
running on it. You just need to make sure each node has enough
resources (CPU and memory primarily and to a lesser extent NIC
throughput and SCSI controller (or SAN HBA) capacity) to support both
instances simultaneously.
It also depends on whether it's acceptable to your business to run both
SQL instances at a degraded performance level until you can get the dead
node back on its feet (assuming the business doesn't want to fork out
the cash to have more CPU & memory in each node in order to adequately
run both instances on one node).
Personally, where I work we run 4 production clusters (each with 2 SQL
instances on it) and an off-site DR cluster (with 2 SQL instances on
it). I can't remember a problem in the last 5 years that we've had on
any instance on our clusters that wouldn't have also happened if we'd
only had a single instance on each cluster (the issue were all OS level
or hardware level issues - to be honest, our stand-alone SQL boxes were
always more stable but obviously didn't have the failover capacity if
something went wrong). However, we tend to run cluster nodes with a
little resource overhead in them in case of a failover.
*mike hodgson*
http://sqlnerd.blogspot.com
John wrote:

>Hello,
>We are going to design our SQL Server databases on either Active/Active or
>Active/Passive of Windows 2003 clusters.
>Has any one seen real time risk and their real experiences of using
>Active/Active clusters?
>Thanks, John
>

Active/Active Clustering - Help!

Hi,
The installation you have in the default instance that
run on the primary node. binaries on C:\ databases on
shared cluster disks.
You have to add a new shared clustered disk to the OS an
then to the cluster, Disk resource.
Then, on secondary Node, Node2, you install a named
instance to the local C:\ (new explicit set of binaries
and executables) and the databases to the new sahred disk.
Now you have to intances, default (node1) and named
(node2) with databases on external disks. Then you
install two Vitual SQL Servers (separate IP addresses)
for each instance. You can add additional named instances
to any other node, if yoy add more disks. With multiple
instances SQL200x also support a local installation on
the local disk of ONE node.
Don't even try this. Maybe in SQL 7 this would work. All this will do with
SQL 2000 is confuse you and break your system.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"Sca" <anonymous@.discussions.microsoft.com> wrote in message
news:24db01c4acba$663fac80$a601280a@.phx.gbl...
> Hi,
> The installation you have in the default instance that
> run on the primary node. binaries on C:\ databases on
> shared cluster disks.
> You have to add a new shared clustered disk to the OS an
> then to the cluster, Disk resource.
> Then, on secondary Node, Node2, you install a named
> instance to the local C:\ (new explicit set of binaries
> and executables) and the databases to the new sahred disk.
> Now you have to intances, default (node1) and named
> (node2) with databases on external disks. Then you
> install two Vitual SQL Servers (separate IP addresses)
> for each instance. You can add additional named instances
> to any other node, if yoy add more disks. With multiple
> instances SQL200x also support a local installation on
> the local disk of ONE node.

Sunday, March 11, 2012

Active directory + list users

I neet save user login form active direcotry to databases. How I can make that?

If you're using Trusted Security to connect to the database (In other words, every single user is authenticated to the database with their windows logon), you could write code like the following at the database level:

INSERT Users
(Username)
(SUSER_SNAME())

SUSER_SNAME, gives you the current authenticated user to the database.

If you're connecting to the database using a Sql Server Login, but are using windows authentication in your .net application you could write the following code:

Dim _sql as string
_sql = "INSERT Users (USERNAME) VALUES ('" + My.User.Name "')"

And just execute this code against the database.

Hope this helps,


Saturday, February 25, 2012

Accomodating Dummy Data?

Hello,

I am working with a vb6 Windows application that runs on Tablet PC's.
There are about five SQL Server 2000 databases that tie into the
application. SQL Server MSDE runs on the tablets, and currently there
is only one instance running. There are efforts underway to upgrade the
application to a .NET SmartClient.

One enhancement that needs to be made to the current application will
be to provide a 'training mode' in the application for the users. The
user will use the same application, but will work with 'dummy' data
instead of live data when in training mode.

So far as I can tell, the easiest way to accomodate this would be to
have a second instance of MSDE with 'copies' of all the databases
running, but with the 'dummy' data contained in the databases copies.
The application would have some mechanism for switching to 'training
mode', and maybe by some change of a connection string, the dummy data
would be presented in the application.

So aside from accomodating a 'training mode' feature in the
application, the application would remain the same, and the database
schema for the databases would remain the same. Only the data would
change for 'training mode'.

I'm looking for some ideas on how to approach this. This application is
used by five thousand field agents, and so we can't support this
implementation on a case by case basis. So my thought is that the
solution needs to have 'few moving parts'. If we can do this and get
away from having two instances of MSDE, that would be great. I have not
tried to set up identical databases in different directories on the
same instance (I figure that would cause a problem in a system table or
two someplace, but maybe not), but its one thing I want to investigate.

If you have any ideas on this, please share!

Thank you for your help!

CSDunnHave multiple copies of the databases and parameterize the connection
strings used by the application so that you can connect to the Live
data set or the Sample data set.

--
David Portas
SQL Server MVP
--

accidentally populate tables into System databases/master database

Hi,

I accidentally populate tables into System databases/master database. What should I do? Should I delete all the tables I populate in mster database?

Thank you very much!

I would transfer the tables and data to the database where they 'should' be located, and then DELETE the ones in the master database.

|||

To move a table to another disk you have to
-create a secondary file group on an another location (or separate) of physical disk.
-drop the clustered index of the table and re-create it on that file group (Alter Table ... | MOVE TO { partition_scheme_name ( column_name ) | filegroup
| "default"}
- see Books Online).

This procedure can be use on large tables; if the size of your tables is not so big you can copy these tables with import/export wizard to a test db and copy backb in database with that filegroup made default.

|||

Thank you All,

I just deleted all the talbes were accidentally created in System/Master Database in sql server 2005. Sql server seems working fine. Smile

Friday, February 24, 2012

accesssing mirrored databases via SQLNCLI linked server?

Does anyone know how to configure a mirrored pair as a linked server on a 3rd instance?

Say I have a mirrored database on two servers: PRIMARY and SECONDARY.

I want to create a linked server on a 3rd machine that allows me to access the database on the mirrored pair.

This is what I'm using:

EXEC master.dbo.sp_addlinkedserver
@.server = N'MIRROR',
@.srvproduct=N'',
@.provider=N'SQLNCLI',
@.provstr=N'Server=PRIMARY;FailoverPartner=SECONDARY;'

select count (*) from mirror.pubs.dbo.authors

and it works fine if the database on PRIMARY is alive. however when the mirror has failed over to SECONDARY and PRIMARY is no longer available, I get the following when I try to query the database via the linked server:

OLE DB provider "SQLNCLI" for linked server "MIRROR" returned message "Login timeout expired".
OLE DB provider "SQLNCLI" for linked server "MIRROR" returned message "An error has occurred while establishing a connection to the server. When
connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.".
Msg 10061, Level 16, State 1, Line 0
TCP Provider: No connection could be made because the target machine actively refused it.

As far as I can tell, it doesn't try to contact SECONDARY at all. It seems like SQL Server is ignoring the FailoverPartner attribute.

If I switch PRIMARY and SECONDARY in the connection string (ie @.provstr=N'Server=SECONDARY;FailoverPartner=PRIMARY;') then it works when SECONDARY is online, but not when the mirror has failed back to PRIMARY.

Any ideas?

Piers.

It is quit possible that the connection to the primary take long to fail before making second connection to the secondary. The default timeout value is 15 seconds for a connection. You can try extend the timeout value or you can upgrade to SP1 which has better retry logic that can deal with timeout better.

|||

I was able to reproduce this problem and we're investigating further. Will let you know the results.

|||great! I'd love to know if there's a workaround or patch available.|||

From the documentation at: ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/dataacc9/html/71b15712-7972-4465-9274-e0ddc271eedc.htm

You must explicitly specify the database to be used by a connection if you want to use this feature in a DSN, connection string, or connection property/attribute. SQL Native Client will not attempt to failover to the partner database if this is not done.

Mirroring is a feature of the database. Applications that use multiple databases might not be able to exploit this feature.

In addition, server names are case insensitive, but database names are case sensitive. You should therefore make sure that you use the same casing in DSNs and connection strings.

So basically you should specify the Database name to which to connect to either in the connection string or through @.catalog=<Database Name> parameter to sp_addlinkedserver. I tried doing that and the repro started working.

Thanks

Waseem

accesssing mirrored databases via SQLNCLI linked server?

Does anyone know how to configure a mirrored pair as a linked server on a 3rd instance?

Say I have a mirrored database on two servers: PRIMARY and SECONDARY.

I want to create a linked server on a 3rd machine that allows me to access the database on the mirrored pair.

This is what I'm using:

EXEC master.dbo.sp_addlinkedserver
@.server = N'MIRROR',
@.srvproduct=N'',
@.provider=N'SQLNCLI',
@.provstr=N'Server=PRIMARY;FailoverPartner=SECONDARY;'

select count (*) from mirror.pubs.dbo.authors

and it works fine if the database on PRIMARY is alive. however when the mirror has failed over to SECONDARY and PRIMARY is no longer available, I get the following when I try to query the database via the linked server:

OLE DB provider "SQLNCLI" for linked server "MIRROR" returned message "Login timeout expired".
OLE DB provider "SQLNCLI" for linked server "MIRROR" returned message "An error has occurred while establishing a connection to the server. When
connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.".
Msg 10061, Level 16, State 1, Line 0
TCP Provider: No connection could be made because the target machine actively refused it.

As far as I can tell, it doesn't try to contact SECONDARY at all. If I switch PRIMARY and SECONDARY in the connection string (ie @.provstr=N'Server=SECONDARY;FailoverPartner=PRIMARY;') then it works when SECONDARY is online, but not when the mirror has failed back to PRIMARY.

Any ideas?

Piers.

It is quit possible that the connection to the primary take long to fail before making second connection to the secondary. The default timeout value is 15 seconds for a connection. You can try extend the timeout value or you can upgrade to SP1 which has better retry logic that can deal with timeout better.|||

All 3 servers are running 9.0.2047sp1/x64 on WS2k3sp1/x64.

I've also tried extending the connection timeout with

EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'connect timeout', @.optvalue=N'120'

but I still get the same error after ~20 seconds (regardless of the value I specify). I've looked at the network traffic and it never seems to attempt to establish a connection to the secondary.

here's the entire script I'm using:

EXEC master.dbo.sp_dropserver @.server= N'MIRROR'

EXEC master.dbo.sp_addlinkedserver
@.server = N'MIRROR',
@.srvproduct=N'',
@.provider=N'SQLOLEDB',
@.provstr=N'Server=PRIMARY;FailoverPartner=SECONDARY;'
GO

EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'collation compatible', @.optvalue=N'true'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'data access', @.optvalue=N'true'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'dist', @.optvalue=N'false'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'pub', @.optvalue=N'false'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'rpc', @.optvalue=N'true'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'rpc out', @.optvalue=N'true'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'sub', @.optvalue=N'false'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'connect timeout', @.optvalue=N'1000'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'collation name', @.optvalue=null
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'lazy schema validation', @.optvalue=N'false'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'query timeout', @.optvalue=N'0'
EXEC master.dbo.sp_serveroption @.server=N'MIRROR', @.optname=N'use remote collation', @.optvalue=N'true'

select top 10 * from MIRROR.pubs.dbo.authors

What am I missing?

Piers.

Accessing two databases simultaneously

I have Crystal Reports 8.5 installed at my site. Was looking at accessing data from 2 databases(Oracle & SQL Server 2000) simultaneously, i.e creating a report which would simultaneously access these 2 data sources. Can you tell me the possibility of doing this.
Thanks.You can make your report connect to SQL Server only..and retrieve Oracle data from SQL Server as a linked server..
this article can give you an idea about this:
How to Link Different Data Sources Together (http://www.dev-archive.com/Csharp/Csharp/cs_data/searching/article.php/c9953/)|||Hi,

I think we need to use Business Views this future is available in Crystal Reports10.
I don't think by using Crystal Reports 8.5 we can achive this...

accessing two databases from a single Stored Procedure

Is it possible to access another database from a single stored procedure of another database. If it is possible, please show how.

If both the DBs are on single Server and the current user have access permission on both database then you can use the following query..

Select SomeColumns From CurrentDBName..TableName
Select SomeColumns From OtherDBName..TableName

If the other database on different database Server then you have to use the Linked Server..

EXEC sp_addlinkedserver @.server = 'SERVER', @.provider = 'SQLOLEDB.1', @.srvproduct = '', @.provstr = 'Privider=SQLOLEDB.1;Data Source=TargetServer;Initial Catalog=Database'

go
Exec sp_addlinkedsrvlogin @.rmtsrvname = 'SERVER', @.useself = true, @.locallogin = null, @.rmtuser = 'Userid', @.rmtpassword = 'Password'


On your SP you can use..

Select * From OpenQuery(MyRemoteServer, 'Select * From Sysobjects')

--OR

Select * From MyRemoteServer.DatabaseName.dbo.Sysobjects

|||

If the databases are on the same server just qualify the tables (in the database) with the database name

i.e.

Assume your stored procedure is in a database called MyDB. In your stored procedure, you can use the follwoing to access tables on from two different databases.

Select col1 from pubs.dbo.authors t1
Inner join adventurewords.dbo.sales t2 on t1.id = t2.id

If the database is on another server, you can create a linked server (and assuming security is OK).

Assume stored procedure is on a database called MyDB on server named Server1 and table you are trying to access is on Server2

Select * from [Server2].pubs.dbo.authors

|||

You can validate the Linked Server already present or not using..

select srvname From Master..sysservers

|||create procedure Proc_name as
begin
select * from database1..Tablename left join
select * from database2..Tablename
end

accessing two databases at once

I'm new to databases as you probably can tell. A friend sent me three data bases, which in my mind should have been one database with all the tables included, but he didn't. So my question is, can you pull info from two databases in the same query?

I write the query acessing one database and the result chart must depend on a where predicate based on accessing tables in another database. If this isn't possible, how do I get the tables I need together, that presently reside in differing databases?

Thanks for the help in advance.

MilfredoYou could access two databases at the same time if you need to.
Example: to copy Table1 from a database called OtherDB to a database called MyDB you can do the following:

select * into MyDB..Table1 from OtherDB..Table1

(Note: the previous will not create constraints nor will it create indexes in MyDB..Table1. You could create the tables first ant then use "insert into")|||Thank you very much.

Milfredo|||can you pull info from two databases in the same queryYes, e.g.select l.sid, l.loginname, u.name
from master..syslogins l
,msdb..sysusers u
where l.sid=u.sid|||Thanks for trying to help. But I'm just a simple guy at home trying to learn to work with SQL. You lost me with the Master reference and basically the whole syntax of the FROM clause.

Thanks anyway.
Milfredo|||Try this ... open up Books Online. Click on the Index tab. Type the following (without the quotes) ... "SELECT, FROM clause". Note the database.owner.table naming structure.|||You can refer two different tables in two different databases provided they are on the same server otherwise a linked server may be required.|||Thanks very much. I just got home from My Daughter's opening day in her new dress shop. So I will tend to database business tomorrow. Thanks again.

Milfred|||I either didn't see it or didn't understand what I was reading. Probably both. So I'm going to try this. I'm going to provide some info, very basic, and see if someone will put it in code for me, so, if I see it, maybe I'll understand.

Two databases: EQRaces EQCharts

While I know this code will be wrong, it should describe visually what I'm trying to do.

Select Horsename AS Name

FROM EQRaces, EQCharts

WHERE PowerRating > 50

Okay...Horsename is in EQCharts and PowerRating is in EQraces

Can someone please show me the right code?

Thanks,
Milfredo

Accessing to another server

Hello there
I have two databases, on two diffrent servers, connected to the same
network.
In order to use them both I:
1. create registry to both servers on the same enterprize manater
2. Set them as remote server on two sides.
Now when i'm trying to access to one server when connecting to other server,
it being connected as Guest. And i would like to access to another server as
Admin, or other user.
How can i do that?Roy
Have you read about Linked Servers?
"roy goldhammer" <roy@.hotmail.com> wrote in message
news:eOinwRG%23FHA.740@.TK2MSFTNGP11.phx.gbl...
> Hello there
> I have two databases, on two diffrent servers, connected to the same
> network.
> In order to use them both I:
> 1. create registry to both servers on the same enterprize manater
> 2. Set them as remote server on two sides.
> Now when i'm trying to access to one server when connecting to other
> server, it being connected as Guest. And i would like to access to another
> server as Admin, or other user.
> How can i do that?
>|||Is there diffrenct between linked server and remote server?
' 03-5611606
' 050-7709399
: roy@.atidsm.co.il
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:OFMRt3J%23FHA.1032@.TK2MSFTNGP11.phx.gbl...
> Roy
> Have you read about Linked Servers?
>
> "roy goldhammer" <roy@.hotmail.com> wrote in message
> news:eOinwRG%23FHA.740@.TK2MSFTNGP11.phx.gbl...
>|||Roy
By creating Linked Server you will be able to query this (remote)
server like SELECT <> FROM Servername.DataBase.dbo.Table WHERE...
By registering a remote server via EM you can olny view a data if you have
an appropriate permissions
One thing I'd like to mention is you can use OPENROWSET command to query
remote server without creating linked server on it.
"Roy Goldhammer" <roy@.hotmail.com> wrote in message
news:eri9hfL%23FHA.160@.TK2MSFTNGP12.phx.gbl...
> Is there diffrenct between linked server and remote server?
> --
>
>
> ' 03-5611606
> ' 050-7709399
> : roy@.atidsm.co.il
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:OFMRt3J%23FHA.1032@.TK2MSFTNGP11.phx.gbl...
>

Accessing the sample database in Visual Basic .net sqlDataAdapter

I need some help with accessing the sample databases with
the SqlDataAdapter.
After double-clicking on SqlDataAdapter in Visual
Basic .net. I click on new connection and choose
Microsoft Ole DB Provider for SQL Server as the
provider. Then under the connection tab, I enter (local)
as the server name. And Choose Use Windows NT Inegrated
Security. Then under databases in the server, only
master, model, msdb, and tempdb show up. The sample
databases Northwind and pubs don't show up, as well as
the database which I created called Project.
In the SQL Server Enterprise Manager, under Console Root -
> Microsoft SQL Server -> SQL Server Group -> CR304216-
A\Project[WindowsNT] -> Databases
I see master, model, msdb, Northwind, Project, pubs, and
tempdb.
So, why don't I see Northwind, Project, and pubs in the
sqlDataAdapter console?Hi, Sabrina!
I'm fairly new to VB.net, but I'm working hard at learning it each day.
Anyway, have you tried using the "sa" user name (or better yet... just the u
ser name and password to one of the databases you have access to)? I tend t
o not use the Windows security and go with the user name and password provid
ed for SQL Server instead (
I seem to have problems getting connections the other way).
I would try that and see what happens.
Hope that helps.
Rick
-- Sabrina wrote: --
I need some help with accessing the sample databases with
the SqlDataAdapter.
After double-clicking on SqlDataAdapter in Visual
Basic .net. I click on new connection and choose
Microsoft Ole DB Provider for SQL Server as the
provider. Then under the connection tab, I enter (local)
as the server name. And Choose Use Windows NT Inegrated
Security. Then under databases in the server, only
master, model, msdb, and tempdb show up. The sample
databases Northwind and pubs don't show up, as well as
the database which I created called Project.
In the SQL Server Enterprise Manager, under Console Root -
> Microsoft SQL Server -> SQL Server Group -> CR304216-
A\Project[WindowsNT] -> Databases
I see master, model, msdb, Northwind, Project, pubs, and
tempdb.
So, why don't I see Northwind, Project, and pubs in the
sqlDataAdapter console?

Thursday, February 16, 2012

Accessing SQL Server Databases from Networked PC

Hello all. I have just built another PC (New PC)and have it connected to my
Original PC via a LAN. I have my SQL Server 2000 installed on the Original
PC. Both PCs use WinXP Pro OS. I believe I now have to install the Client
Tools on the New PC but after that, how do I access the SQL Server that is
on the Original PC. The SQL Server is setup with mixed (both Windows
Authentication and SQL Server Authentication). Just how do I use the SQL
Query Analyzer that I just installed on the New PC to connect to and
retreive data from the SQL Databases which are on the Original PC? Thanks
in advance for any help, Jim.Hello all. Dissregard this request for assistance as I was able to figure it
out. I can now connect the New PC to the SQL Server in the Original PC,
write my query and the results are displayed on the New PC over the Network.
Have a good day. Jim.

"Jim Richards" <JWRichards@.satx.rr.com> wrote in message
news:RGoOd.38259$uA.22293@.fe1.texas.rr.com...
> Hello all. I have just built another PC (New PC)and have it connected to
> my Original PC via a LAN. I have my SQL Server 2000 installed on the
> Original PC. Both PCs use WinXP Pro OS. I believe I now have to install
> the Client Tools on the New PC but after that, how do I access the SQL
> Server that is on the Original PC. The SQL Server is setup with mixed
> (both Windows Authentication and SQL Server Authentication). Just how do I
> use the SQL Query Analyzer that I just installed on the New PC to connect
> to and retreive data from the SQL Databases which are on the Original PC?
> Thanks in advance for any help, Jim.

Monday, February 13, 2012

Accessing SQL Mobile Databases in VB2005 - Pocket PCApp


I am using VS 2005 to develop a Pocket PC 2003 application and for some reason I dont have the ability to assign my datasource to a SQL Mobile Database?

When opening Server Explorer, right clicking Data Connection, Add New Data Source, Change Data Source, the only options I get are

Microsoft Access Database File
Microsoft ODBC Data Source
Microsoft SQL Server
Microsoft SQL Server Database File
Oracle Database
<other>

I was trying to follow the tutorial

Step by Step: Developing a SQL Mobile Application with Visual Studio 2005 and SQL Server 2005 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppcgen/html/med302_msdn_sql_mobile.asp)

and in that tutorial when they do the exact same thing it shows a screen shot that also lists 'Microsoft SQL Server Mobile Edition'

Any ideas why I dont have that option? FYI, I have SQL Server 2005 and have installed SQL Server 2005 Mobile Edition.

Thanks

Mike

Can you please have a look at @. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=260599&SiteID=1 and try the machine.config solution given.

Thanks,

Laxmi Narsimha Rao ORUGANTI, MSFT, SQL Mobile, Microsoft Corporation

|||Right on! Thanks so much, would of never figured that out! Noooooowwww, VS 2005 is working how it should and I'm much more impressed.
|||

Glad to hear that things working from your side. Thanks for using Microsoft Products and SQL Mobile.

Thanks,

Laxmi Narsimha Rao ORUGANTI, MSFT, SQL Mobile, Microsoft Corporation

accessing result of sp_tables

When I run exec sp_tables it give me a "list" of tables in databases. In fact the result is a table where one of the columns contains the database table names. It is no problem to access it in a client application but I need to access that column and verify existance of a certain table in SQL Server's user stored procedure. So far anything I tried did not work. FETCH pertains to a cursor and I cannot declare a cursor for this command. The only thing I got so far was @.@.ROWCOUNT but it is of no use for me. Perhaps there is another way to verify if a table exists from inside a stored procedure.

I have the same problem in terms of verifying existence of a user stored procedure from inside another user stored procedure but if I get help on the first point, this one will be no brainer.

Thanks.

WHat abou tusing the INFORMATION_SCHEMA.Tables view ? I did not get what you are trying to achieve. If the tables are listed there, they are existing on the database. Or do you want to check another database for the tables ?

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de|||

Jens K. Suessmeyer wrote:

WHat abou tusing the INFORMATION_SCHEMA.Tables view ? I did not get what you are trying to achieve. If the tables are listed there, they are existing on the database. Or do you want to check another database for the tables ?

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

Hi Jens,

I do use INFORMATION_SCHEMA in my C# app but now I need to get this information in a stored procedure in SQL Server itself. Everything is confined to the same database boundary. The problem is: I am trying to optimize some operations in terms of performance and disk space. My records are first written in a common table. There might be a up to 100,000 records per day or more. All records are dated of course, so I can pull records for one day at will. All records for a day may be broken into up to 20 categories (symbols). They have a column (field) called symbol, After accumulating records for a few days, let say 5, I want to select all records for the latest date and insert them into a SEPARATE tables for each symbol. Then these records will be purged from the common table for good. The symbol column is absent in those tables but the symbol is part of their name, e.g "table_MSFT" Now, I do not want to create those tables in advance since it may lead to confusion. I want my stored procedure to be able to create a table once it found that a new symbol just appeared in the first, common table. It may be tomorrow or two months from now.

The reason I try to implement a design like this is that if I have to create tables half a year from now it will be hard to recall all the details and the errors will be inevitable. I want to invest time now and make it automatic for all time.

I actually solved the problem in terms of what I've tried to achieve. I do not know why it did not work for me the first time around, some goofy bug got on the way perhaps, but now it works very well. The way I do it is as follows:

exec sp_tables <tableName> This gives me just one row. I check @.@.ROWCOUNT and if it is 0, the table is created on the fly. I have done it many times already.

HOWEVER, I really want to get access to the columns in that row (or rows if I use exec sp_tables with no argument). I want to be able to access the fields and test the values if I need it. I know I will need it in the future. I am wondering if you are aware of a simple way to accomplish it.

If you do not know how to do it or it is not feasible to do, I want to consider CLR stored procedures. In other words I can write a C# code that will do it and store it in SQL Server. I have never done it and have a vague understanding how they work, how they are stored and how the information is retrieved from them. Remember, I want to use those stored procedures inside other stored procedures on the Server. In the client app it is all very simple.

Many thanks for your help.

|||

Jens K. Suessmeyer wrote:

WHat abou tusing the INFORMATION_SCHEMA.Tables view ? I did not get what you are trying to achieve. If the tables are listed there, they are existing on the database. Or do you want to check another database for the tables ?

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

OK Jens,

This is the idea I have decided to try. What if I take a system stored procedure sys.sp_stored_procedures, change its name and modify it in such a way that it will store resulting table of the existing stored procedures either in a temporary table or even in a special permanent workbench table created specifically for this purpose. I had to change the name of the procedure to dbo.mine_sp_stored_procedures because otherwise I was getting an error on the first line but then the things proceeded smoothly (seemingly) in terms of its being executed with no errors.

However, when I tried to run it with parameters or without it broke down because it could not find certain objects. One of them is sys.numbered_procedures$. It is on line 118. The line numbering I found meaningless. The line number you get in the messages window does no correspond to anything in the code and if you try to find this line with Edit-->Go TO you will never find what you want.

Anyway, my knowledge base is too week at this point to find a way around it, how to handle it. Perhaps you may have an idea.

Thanks.

|||Hi Alex,

I don′t know if I got you right, but here is an option for getting the results from a stored procedure and looping through the details:

IF OBJECT_ID('tempdb..#SomeTable') IS NOT NULL

Drop Table #SomeTable

CREATE TABLE #SomeTable

(

Ident INT IDENTITY(1,1),

A int,

B varchar(60),

C varchar(255)

)

DECLARE @.I INT

DECLARE @.ROWCOUNT INT

SET @.I = 0

INSERT INTO #SomeTable

(

A,B,C

)

EXEC SP_Server_info

SET @.RowCount = @.@.ROWCOUNT

WHILE @.I<= @.RowCount

BEGIN

Select * From #SomeTable

Where Ident = @.I

SET @.I = @.I +1

END

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

Jens K. Suessmeyer wrote:

Hi Alex,

I don′t know if I got you right, but here is an option for getting the results from a stored procedure and looping through the details:

IF OBJECT_ID('tempdb..#SomeTable') IS NOT NULL

..........................................
HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

I just tried it. Thanks you very much. It worked. It looks like it is what I may use. I think this is the answer. So much for mine_stored_procedures:) But it is a good news.

Accessing Reports/Databases across 2 domains

I have architecture related question -
I have 2 databases on 2 domains and security doesn't permit me to co-mingle
the data. I'll be generating 2 different reports for same request.
Question is - Do I need SQL server with reporting services installed on
each domain?
Current proposed solution is -
Domain AAA will have SQL server with RSS
Domain BBB will have SQL server with RSS
Sharepoint web parts (on BBB side) will access report from AAA and BBB.
(Domain BBB has 1 port open to allow web traffic).
If trusted SQL server connection is made available to RSS on BBB side, then
I think we don't need server with RSS on domain AAA. is this right? If so,
How can I access databases from RSS across domains?
Sounds interesing right? Please help me ....Sonali,
RSS is only needed to host the report definition which in turn collects
the data required. Provided the data connections are set up with
appropriate logins to the databases on each domain from the RS server,
you should be able to run from one RS server.
Your issue will be if your security policies totally prevent any access
between the domains.
Chris
Sonali wrote:
> I have architecture related question -
> I have 2 databases on 2 domains and security doesn't permit me to
> co-mingle the data. I'll be generating 2 different reports for same
> request.
> Question is - Do I need SQL server with reporting services installed
> on each domain?
> Current proposed solution is -
> Domain AAA will have SQL server with RSS
> Domain BBB will have SQL server with RSS
> Sharepoint web parts (on BBB side) will access report from AAA and
> BBB. (Domain BBB has 1 port open to allow web traffic).
> If trusted SQL server connection is made available to RSS on BBB
> side, then I think we don't need server with RSS on domain AAA. is
> this right? If so, How can I access databases from RSS across domains?
> Sounds interesing right? Please help me ....

Sunday, February 12, 2012

accessing remote databases thru agent jobs

We have some agents jobs which are run on schedule.
The agent jobs call stored procedures created on
local databases.
We want to move the agent jobs to a different server
(remote server). How do we set up accessing the databases
from the remote server so that none of the agent jobs need to
be changed, or with minimum change.
TIA.You would have to set up linked severs. For more information and examples,
see sp_addlinkedserver, sp_addlinkedsrvlogin, sp_serveroption in SQL Server
Books Online.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Data Cruncher" <dcruncher4@.netscape.net> wrote in message
news:1121880962.361317.54810@.g44g2000cwa.googlegroups.com...
> We have some agents jobs which are run on schedule.
> The agent jobs call stored procedures created on
> local databases.
> We want to move the agent jobs to a different server
> (remote server). How do we set up accessing the databases
> from the remote server so that none of the agent jobs need to
> be changed, or with minimum change.
> TIA.
>|||Narayana Vyas Kondreddi wrote:
> You would have to set up linked severs. For more information and examples,
> see sp_addlinkedserver, sp_addlinkedsrvlogin, sp_serveroption in SQL Server
> Books Online.
I too thought about the linked server option, but it seems it
still requires using a linked server name as the qualifier
for the database name.
this is the original code of the Agent job
-- Add the job steps
EXECUTE @.ReturnCode = msdb.dbo.sp_add_jobstep @.job_id = @.JobID,
@.step_id = 1, @.step_name =N'Purge', @.command = N'exec bts_CleanupDeadProcesses', @.database_name =N'BizTalkMsgBoxDb',
@.server = N'', @.database_user_name = N'', @.subsystem = N'TSQL',
@.cmdexec_success_code = 0, @.flags
= 0, @.retry_attempts = 0, @.retry_interval = 1, @.output_file_name = N'',
@.on_success_step_id = 0,
@.on_success_action = 1, @.on_fail_step_id = 0, @.on_fail_action = 2
Now how do i make the agent job refer to a remote database at the
parameter @.database_name = N'BizTalkMsgBoxDb' without qualifying it
with the linked server.
Thanks for your help.|||Narayana Vyas Kondreddi wrote:
> You would have to set up linked severs. For more information and examples,
> see sp_addlinkedserver, sp_addlinkedsrvlogin, sp_serveroption in SQL Server
That's what my initial guess was. However when I add
a linked server, in the SQL Agent Job, I still need to
qualify the database name from MyDB to LINKEDSERVER.MyDB.
is there a way to avoid it. That is, is there a way for
Agent job to know the context of server is LINKEDSERVER.
Thanks for your help.|||No. Instead you could have a constant linked server name, by adding an alias
on the server, using Client Network Utility, and by adding a linked server
using the alias name. this way you could change the server name, but still
keep the same alias name.
Anyway, makes me curious why are you movig the job to a different server?
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Data Cruncher" <dcruncher4@.netscape.net> wrote in message
news:1121884794.983994.137000@.g43g2000cwa.googlegroups.com...
>
> Narayana Vyas Kondreddi wrote:
>> You would have to set up linked severs. For more information and
>> examples,
>> see sp_addlinkedserver, sp_addlinkedsrvlogin, sp_serveroption in SQL
>> Server
> That's what my initial guess was. However when I add
> a linked server, in the SQL Agent Job, I still need to
> qualify the database name from MyDB to LINKEDSERVER.MyDB.
> is there a way to avoid it. That is, is there a way for
> Agent job to know the context of server is LINKEDSERVER.
> Thanks for your help.
>|||Narayana Vyas Kondreddi wrote:
> No. Instead you could have a constant linked server name, by adding an alias
> on the server, using Client Network Utility, and by adding a linked server
> using the alias name. this way you could change the server name, but still
> keep the same alias name.
I am not sure how the above is relevant to my case. Please refer to
the code example I have posted in the other reply.
> Anyway, makes me curious why are you movig the job to a different server?
as you can see from the code snippet it is Biztalk jobs. We
are going to host our production server with a hosting company
and they do not support running application jobs on the
database server. So I am doing pro/con matrix to see how
much we have to change.|||Okay, you will have to make a change to the job step, if the server context
has to change.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Data Cruncher" <dcruncher4@.netscape.net> wrote in message
news:1121888749.038267.117940@.g49g2000cwa.googlegroups.com...
> Narayana Vyas Kondreddi wrote:
>> No. Instead you could have a constant linked server name, by adding an
>> alias
>> on the server, using Client Network Utility, and by adding a linked
>> server
>> using the alias name. this way you could change the server name, but
>> still
>> keep the same alias name.
> I am not sure how the above is relevant to my case. Please refer to
> the code example I have posted in the other reply.
>> Anyway, makes me curious why are you movig the job to a different server?
> as you can see from the code snippet it is Biztalk jobs. We
> are going to host our production server with a hosting company
> and they do not support running application jobs on the
> database server. So I am doing pro/con matrix to see how
> much we have to change.
>

accessing remote databases thru agent jobs

We have some agents jobs which are run on schedule.
The agent jobs call stored procedures created on
local databases.
We want to move the agent jobs to a different server
(remote server). How do we set up accessing the databases
from the remote server so that none of the agent jobs need to
be changed, or with minimum change.
TIA.
You would have to set up linked severs. For more information and examples,
see sp_addlinkedserver, sp_addlinkedsrvlogin, sp_serveroption in SQL Server
Books Online.
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Data Cruncher" <dcruncher4@.netscape.net> wrote in message
news:1121880962.361317.54810@.g44g2000cwa.googlegro ups.com...
> We have some agents jobs which are run on schedule.
> The agent jobs call stored procedures created on
> local databases.
> We want to move the agent jobs to a different server
> (remote server). How do we set up accessing the databases
> from the remote server so that none of the agent jobs need to
> be changed, or with minimum change.
> TIA.
>
|||Narayana Vyas Kondreddi wrote:
> You would have to set up linked severs. For more information and examples,
> see sp_addlinkedserver, sp_addlinkedsrvlogin, sp_serveroption in SQL Server
> Books Online.
I too thought about the linked server option, but it seems it
still requires using a linked server name as the qualifier
for the database name.
this is the original code of the Agent job
-- Add the job steps
EXECUTE @.ReturnCode = msdb.dbo.sp_add_jobstep @.job_id = @.JobID,
@.step_id = 1, @.step_name =
N'Purge', @.command = N'exec bts_CleanupDeadProcesses', @.database_name =
N'BizTalkMsgBoxDb',
@.server = N'', @.database_user_name = N'', @.subsystem = N'TSQL',
@.cmdexec_success_code = 0, @.flags
= 0, @.retry_attempts = 0, @.retry_interval = 1, @.output_file_name = N'',
@.on_success_step_id = 0,
@.on_success_action = 1, @.on_fail_step_id = 0, @.on_fail_action = 2
Now how do i make the agent job refer to a remote database at the
parameter @.database_name = N'BizTalkMsgBoxDb' without qualifying it
with the linked server.
Thanks for your help.
|||Narayana Vyas Kondreddi wrote:
> You would have to set up linked severs. For more information and examples,
> see sp_addlinkedserver, sp_addlinkedsrvlogin, sp_serveroption in SQL Server
That's what my initial guess was. However when I add
a linked server, in the SQL Agent Job, I still need to
qualify the database name from MyDB to LINKEDSERVER.MyDB.
is there a way to avoid it. That is, is there a way for
Agent job to know the context of server is LINKEDSERVER.
Thanks for your help.
|||No. Instead you could have a constant linked server name, by adding an alias
on the server, using Client Network Utility, and by adding a linked server
using the alias name. this way you could change the server name, but still
keep the same alias name.
Anyway, makes me curious why are you movig the job to a different server?
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Data Cruncher" <dcruncher4@.netscape.net> wrote in message
news:1121884794.983994.137000@.g43g2000cwa.googlegr oups.com...
>
> Narayana Vyas Kondreddi wrote:
> That's what my initial guess was. However when I add
> a linked server, in the SQL Agent Job, I still need to
> qualify the database name from MyDB to LINKEDSERVER.MyDB.
> is there a way to avoid it. That is, is there a way for
> Agent job to know the context of server is LINKEDSERVER.
> Thanks for your help.
>
|||Narayana Vyas Kondreddi wrote:
> No. Instead you could have a constant linked server name, by adding an alias
> on the server, using Client Network Utility, and by adding a linked server
> using the alias name. this way you could change the server name, but still
> keep the same alias name.
I am not sure how the above is relevant to my case. Please refer to
the code example I have posted in the other reply.

> Anyway, makes me curious why are you movig the job to a different server?
as you can see from the code snippet it is Biztalk jobs. We
are going to host our production server with a hosting company
and they do not support running application jobs on the
database server. So I am doing pro/con matrix to see how
much we have to change.
|||Okay, you will have to make a change to the job step, if the server context
has to change.
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Data Cruncher" <dcruncher4@.netscape.net> wrote in message
news:1121888749.038267.117940@.g49g2000cwa.googlegr oups.com...
> Narayana Vyas Kondreddi wrote:
> I am not sure how the above is relevant to my case. Please refer to
> the code example I have posted in the other reply.
>
> as you can see from the code snippet it is Biztalk jobs. We
> are going to host our production server with a hosting company
> and they do not support running application jobs on the
> database server. So I am doing pro/con matrix to see how
> much we have to change.
>

accessing remote databases thru agent jobs

We have some agents jobs which are run on schedule.
The agent jobs call stored procedures created on
local databases.
We want to move the agent jobs to a different server
(remote server). How do we set up accessing the databases
from the remote server so that none of the agent jobs need to
be changed, or with minimum change.
TIA.You would have to set up linked severs. For more information and examples,
see sp_addlinkedserver, sp_addlinkedsrvlogin, sp_serveroption in SQL Server
Books Online.
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Data Cruncher" <dcruncher4@.netscape.net> wrote in message
news:1121880962.361317.54810@.g44g2000cwa.googlegroups.com...
> We have some agents jobs which are run on schedule.
> The agent jobs call stored procedures created on
> local databases.
> We want to move the agent jobs to a different server
> (remote server). How do we set up accessing the databases
> from the remote server so that none of the agent jobs need to
> be changed, or with minimum change.
> TIA.
>|||Narayana Vyas Kondreddi wrote:
> You would have to set up linked severs. For more information and examples,
> see sp_addlinkedserver, sp_addlinkedsrvlogin, sp_serveroption in SQL Serve
r
> Books Online.
I too thought about the linked server option, but it seems it
still requires using a linked server name as the qualifier
for the database name.
this is the original code of the Agent job
-- Add the job steps
EXECUTE @.ReturnCode = msdb.dbo.sp_add_jobstep @.job_id = @.JobID,
@.step_id = 1, @.step_name =
N'Purge', @.command = N'exec bts_CleanupDeadProcesses', @.database_name =
N'BizTalkMsgBoxDb',
@.server = N'', @.database_user_name = N'', @.subsystem = N'TSQL',
@.cmdexec_success_code = 0, @.flags
= 0, @.retry_attempts = 0, @.retry_interval = 1, @.output_file_name = N'',
@.on_success_step_id = 0,
@.on_success_action = 1, @.on_fail_step_id = 0, @.on_fail_action = 2
Now how do i make the agent job refer to a remote database at the
parameter @.database_name = N'BizTalkMsgBoxDb' without qualifying it
with the linked server.
Thanks for your help.|||Narayana Vyas Kondreddi wrote:[vbcol=seagreen]
> You would have to set up linked severs. For more information and examples,
> see sp_addlinkedserver, sp_addlinkedsrvlogin, sp_serveroption in SQL Server[/vbcol
]
That's what my initial guess was. However when I add
a linked server, in the SQL Agent Job, I still need to
qualify the database name from MyDB to LINKEDSERVER.MyDB.
is there a way to avoid it. That is, is there a way for
Agent job to know the context of server is LINKEDSERVER.
Thanks for your help.|||No. Instead you could have a constant linked server name, by adding an alias
on the server, using Client Network Utility, and by adding a linked server
using the alias name. this way you could change the server name, but still
keep the same alias name.
Anyway, makes me curious why are you movig the job to a different server?
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Data Cruncher" <dcruncher4@.netscape.net> wrote in message
news:1121884794.983994.137000@.g43g2000cwa.googlegroups.com...
>
> Narayana Vyas Kondreddi wrote:
> That's what my initial guess was. However when I add
> a linked server, in the SQL Agent Job, I still need to
> qualify the database name from MyDB to LINKEDSERVER.MyDB.
> is there a way to avoid it. That is, is there a way for
> Agent job to know the context of server is LINKEDSERVER.
> Thanks for your help.
>|||Narayana Vyas Kondreddi wrote:
> No. Instead you could have a constant linked server name, by adding an ali
as
> on the server, using Client Network Utility, and by adding a linked server
> using the alias name. this way you could change the server name, but still
> keep the same alias name.
I am not sure how the above is relevant to my case. Please refer to
the code example I have posted in the other reply.

> Anyway, makes me curious why are you movig the job to a different server?
as you can see from the code snippet it is Biztalk jobs. We
are going to host our production server with a hosting company
and they do not support running application jobs on the
database server. So I am doing pro/con matrix to see how
much we have to change.|||Okay, you will have to make a change to the job step, if the server context
has to change.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"Data Cruncher" <dcruncher4@.netscape.net> wrote in message
news:1121888749.038267.117940@.g49g2000cwa.googlegroups.com...
> Narayana Vyas Kondreddi wrote:
> I am not sure how the above is relevant to my case. Please refer to
> the code example I have posted in the other reply.
>
> as you can see from the code snippet it is Biztalk jobs. We
> are going to host our production server with a hosting company
> and they do not support running application jobs on the
> database server. So I am doing pro/con matrix to see how
> much we have to change.
>

Thursday, February 9, 2012

Accessing Multiple databases from Stored procedure in SQL 2000

Hi ,

I have around 5 databases with same structure used to store data for different locations and services.

I have created an intermediate database which will have all the stored procedures to access data from above 5 databases.

My queries are common to all the databases. so,I would like to pass database name as an argument to my stored proc and execure query on specified database.

I tried this doing using "USE Databasename " Command. but it says ...We can not use "USE command " in stored proc or triggers. so ..what i did is ..

--

CREATE PROCEDURE TestDB_access(@.dbname varchar(100))
AS

BEGIN

DECLARE @.localDB varchar(100)

Set @.LocalDB=@.dbname

if @.LocalDB='XYZ'

EXEC ('USE XYZ ')
elseif @.LocalDB='ABC'

EXEC ('USE ABC')


Select * from Mytable

END

When I run this from my database , it gives me an error "unable to find table "mytable".

What is the best way to make my queries work with all the databases.

Thanks in advance

Venu Yankarla

Not sure what you are exactly trying to do but you can qualify a table with a database name and use it that way, however there is a limit in an SP of referring to 8 databases.

Try something like select * from Pubs..Authors where Pubs is the db name

|||

Thank you for your reply.

I can use the query "select * from Pubs..Authors where Pubs is the db name " if i know from which database i need to get the data.

In my case ... I want this dbname as a parameter to stored procedure. I can pass this to stored proc as parameter and bulid a string for SQL query and execute it. But I feel this as time consuming process as my queries will have atleast 5 joins in one query.

So , what I am looking for is .... Can we execute a query related to tables from a database (ABC or DEF or ETC) by using a stored proc in a database (XYZ)

Common thing in my case ..all databases has the same table structures but different data related to different locations.

in Query analyzer , we can execute queries on database (ABC or DEF) by staying in database (XYZ) using statement USE ABC and then execute SQL query.

USE ABC will change the database context and execute the query on "ABC" db tables.

Hope ..I am clear now..

Thanks

Venu yankarla

|||I think you will have to use sp_executesql for this