Showing posts with label basic. Show all posts
Showing posts with label basic. Show all posts

Wednesday, March 28, 2012

Question regarding stored procs

Hello,

It might be a basic question, but there it goes:

I have a store procedure that first checks if the record exists and, if
it doesn't, inserts the new record.

Is the scenario below possible?

(thread1) USER1 -> check if record "abc" exists
(thread2) USER2 -> check if record "abc" exists
(thread1) USER1 -> "abc" doesn't exist
(thread2) USER2 -> "abc" doesn't exist
(thread1) USER1 -> add "abc" as new record
(thread2) USER2 -> add "abc as new record (OPS, this is an error,
because "abc" already exists, it was just inserted by USER1)

I am wondering if this kind of concurrent, multi-threaded access
happens with stored procedures.

If yes, can I execute a procedure from start to finish without any
other simultaneous procedure interrupting?

I appreciate any information about this.

Leonardo.Hi Leonardo,

The answer to your first question is yes; if you do not establish a
transaction (with the appropriate locking mechanism), then you can have
concurrency issues. However, you can establish a transaction and set
the isolation level to a higher restriction to avoid this scenario.

Check the SQL Server Books OnLine for transactions and transaction
isolation levels; that should get you started.

HTH,
Stu|||(leodippolito@.gmail.com) writes:
> It might be a basic question, but there it goes:
> I have a store procedure that first checks if the record exists and, if
> it doesn't, inserts the new record.
> Is the scenario below possible?
> (thread1) USER1 -> check if record "abc" exists
> (thread2) USER2 -> check if record "abc" exists
> (thread1) USER1 -> "abc" doesn't exist
> (thread2) USER2 -> "abc" doesn't exist
> (thread1) USER1 -> add "abc" as new record
> (thread2) USER2 -> add "abc as new record (OPS, this is an error,
> because "abc" already exists, it was just inserted by USER1)

Yes.

> I am wondering if this kind of concurrent, multi-threaded access
> happens with stored procedures.
> If yes, can I execute a procedure from start to finish without any
> other simultaneous procedure interrupting?

You would need to enclose the IF EXISTS + SELECT in a transaction.
Furthermore, you must make sure that the isolation level is serializable.
The defuault isolation level in SQL Server is READ COMMITTED, which
means that once the EXISTS check has passed, locks are released.

The best solution is to add the table hint "WITH (UPDLOCK)" in the
EXISTS query. This would make USER2 in this example to be blocked
already at this point. If you just use SET TRANSACTION ISOLATION
LEVEL, the two processes will deadlock.

One way to test issues like this, is to insert a WAITFOR in the code,
and then run from separate windows in Query Analyzer.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Erland, why do you say " If you just use SET TRANSACTION ISOLATION
LEVEL, the two processes will deadlock." ?

Suppose T1 executes with SERIALIZABLE and T2 tries to execute the same
proc at the same time ... Well, as far as I understand, T2 will wait
for T1 to finish and then go on.. right? Why exactly is " WITH
(UPDLOCK) " necessary?

If it's not a problem for you, could you provide me a safe (deadlock
free) example of insert procedure that would check the existance of the
record before inserting?

Thanks for all.

Leonardo.|||(leodippolito@.gmail.com) writes:
> Erland, why do you say " If you just use SET TRANSACTION ISOLATION
> LEVEL, the two processes will deadlock." ?
> Suppose T1 executes with SERIALIZABLE and T2 tries to execute the same
> proc at the same time ... Well, as far as I understand, T2 will wait
> for T1 to finish and then go on.. right? Why exactly is " WITH
> (UPDLOCK) " necessary?

Because with plain serializable this happens:

T1 performs NOT EXISTS check, and retains a shared lock
T2 performs NOT EXISTS check, and retains a shared lock
T1 tries to insert, but is blocked by T2
T2 tries to insert, but is blocked by T1
=> Deadlock

UPDLOCK is a shared lock, so it does not block other readers. However,
only one process have an UPDLOCK on a resource, so T2 would be blocked
until T1 has committed. And when T2 goes ahead, T2 finds that the rows
is already there, and does not try to insert.

> If it's not a problem for you, could you provide me a safe (deadlock
> free) example of insert procedure that would check the existance of the
> record before inserting?

Hey, that's what I leave as an exercise to the reader. :-) Seriously,
I encourage you to try these things by running from separate windows
in Query Analyzer, and try the various possibilities, to see what deadlocks,
what gives errors and what works smoothly. This is a good lab exercise
to get an understanding of things. What is problematic is to emulate
the concurrency, but some WAITFOR statements are usually good enough.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

Monday, March 26, 2012

Question regarding .LDF and .MDF files and backup

Hello,
I have pretty basic question regarding databases on my MS SQL server.
There are .MDF and .LDF files. From what I can tell (and I may well be VERY
wrong here), the MDF file is the REAL data. The LDF file are changes yet to
be merged into the live data.
1 - What are the LDF files?
2 - Why are they so big? Do they never flush?
3 - When do "transactions" become part of the "data"?
4 - If I want to make a Full backup of a database can I make a full database
backup or do I need to make a logfiles backup also to get a "full backup".
The database is not written so often to so a full backup each night is
enough.
Thanks in advance.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Magnus" <Magnus@.discussions.microsoft.com> wrote in message
news:C5C38AE4-1C1D-4B1F-BEB7-D22565A8FE8E@.microsoft.com...
> Hello,
> I have pretty basic question regarding databases on my MS SQL server.
> There are .MDF and .LDF files. From what I can tell (and I may well be
VERY
> wrong here), the MDF file is the REAL data. The LDF file are changes yet
to
> be merged into the live data.
> 1 - What are the LDF files?
The transaction log.
> 2 - Why are they so big? Do they never flush?
They grow until you either backup the log, or set the database to Simple
recovery mode
> 3 - When do "transactions" become part of the "data"?
Immediately when the transaction commits
> 4 - If I want to make a Full backup of a database can I make a full
database
> backup or do I need to make a logfiles backup also to get a "full backup".
> The database is not written so often to so a full backup each night is
> enough.
Set the database to Simple recovery mode, then backup the entire database
nightly... You will loose any transactions since the last full backup.
>
> Thanks in advance.
|||There is a section in BOL titled "Physical Database Architecture",
explaining the files and their usage. The section title "Backup/Restore
Architecture" will also be useful.
"Magnus" <Magnus@.discussions.microsoft.com> wrote in message
news:C5C38AE4-1C1D-4B1F-BEB7-D22565A8FE8E@.microsoft.com...
> Hello,
> I have pretty basic question regarding databases on my MS SQL server.
> There are .MDF and .LDF files. From what I can tell (and I may well be
VERY
> wrong here), the MDF file is the REAL data. The LDF file are changes yet
to
> be merged into the live data.
> 1 - What are the LDF files?
> 2 - Why are they so big? Do they never flush?
> 3 - When do "transactions" become part of the "data"?
> 4 - If I want to make a Full backup of a database can I make a full
database
> backup or do I need to make a logfiles backup also to get a "full backup".
> The database is not written so often to so a full backup each night is
> enough.
>
> Thanks in advance.
|||Some information scattered in these articles about why log files are
large...
http://www.aspfaq.com/2446
http://www.aspfaq.com/2471
http://www.aspfaq.com/
(Reverse address to reply.)
"Magnus" <Magnus@.discussions.microsoft.com> wrote in message
news:C5C38AE4-1C1D-4B1F-BEB7-D22565A8FE8E@.microsoft.com...
> Hello,
> I have pretty basic question regarding databases on my MS SQL server.
> There are .MDF and .LDF files. From what I can tell (and I may well be
VERY
> wrong here), the MDF file is the REAL data. The LDF file are changes yet
to
> be merged into the live data.
> 1 - What are the LDF files?
> 2 - Why are they so big? Do they never flush?
> 3 - When do "transactions" become part of the "data"?
> 4 - If I want to make a Full backup of a database can I make a full
database
> backup or do I need to make a logfiles backup also to get a "full backup".
> The database is not written so often to so a full backup each night is
> enough.
>
> Thanks in advance.

Question regarding .LDF and .MDF files and backup

Hello,
I have pretty basic question regarding databases on my MS SQL server.
There are .MDF and .LDF files. From what I can tell (and I may well be VERY
wrong here), the MDF file is the REAL data. The LDF file are changes yet to
be merged into the live data.
1 - What are the LDF files?
2 - Why are they so big? Do they never flush?
3 - When do "transactions" become part of the "data"?
4 - If I want to make a Full backup of a database can I make a full database
backup or do I need to make a logfiles backup also to get a "full backup".
The database is not written so often to so a full backup each night is
enough.
Thanks in advance.--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Magnus" <Magnus@.discussions.microsoft.com> wrote in message
news:C5C38AE4-1C1D-4B1F-BEB7-D22565A8FE8E@.microsoft.com...
> Hello,
> I have pretty basic question regarding databases on my MS SQL server.
> There are .MDF and .LDF files. From what I can tell (and I may well be
VERY
> wrong here), the MDF file is the REAL data. The LDF file are changes yet
to
> be merged into the live data.
> 1 - What are the LDF files?
The transaction log.
> 2 - Why are they so big? Do they never flush?
They grow until you either backup the log, or set the database to Simple
recovery mode
> 3 - When do "transactions" become part of the "data"?
Immediately when the transaction commits
> 4 - If I want to make a Full backup of a database can I make a full
database
> backup or do I need to make a logfiles backup also to get a "full backup".
> The database is not written so often to so a full backup each night is
> enough.
Set the database to Simple recovery mode, then backup the entire database
nightly... You will loose any transactions since the last full backup.
>
> Thanks in advance.|||There is a section in BOL titled "Physical Database Architecture",
explaining the files and their usage. The section title "Backup/Restore
Architecture" will also be useful.
"Magnus" <Magnus@.discussions.microsoft.com> wrote in message
news:C5C38AE4-1C1D-4B1F-BEB7-D22565A8FE8E@.microsoft.com...
> Hello,
> I have pretty basic question regarding databases on my MS SQL server.
> There are .MDF and .LDF files. From what I can tell (and I may well be
VERY
> wrong here), the MDF file is the REAL data. The LDF file are changes yet
to
> be merged into the live data.
> 1 - What are the LDF files?
> 2 - Why are they so big? Do they never flush?
> 3 - When do "transactions" become part of the "data"?
> 4 - If I want to make a Full backup of a database can I make a full
database
> backup or do I need to make a logfiles backup also to get a "full backup".
> The database is not written so often to so a full backup each night is
> enough.
>
> Thanks in advance.|||Some information scattered in these articles about why log files are
large...
http://www.aspfaq.com/2446
http://www.aspfaq.com/2471
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Magnus" <Magnus@.discussions.microsoft.com> wrote in message
news:C5C38AE4-1C1D-4B1F-BEB7-D22565A8FE8E@.microsoft.com...
> Hello,
> I have pretty basic question regarding databases on my MS SQL server.
> There are .MDF and .LDF files. From what I can tell (and I may well be
VERY
> wrong here), the MDF file is the REAL data. The LDF file are changes yet
to
> be merged into the live data.
> 1 - What are the LDF files?
> 2 - Why are they so big? Do they never flush?
> 3 - When do "transactions" become part of the "data"?
> 4 - If I want to make a Full backup of a database can I make a full
database
> backup or do I need to make a logfiles backup also to get a "full backup".
> The database is not written so often to so a full backup each night is
> enough.
>
> Thanks in advance.

Wednesday, March 21, 2012

Question on SQL

Good Day,
I have a simple question on SQL 2000. Please note that I am no expert and
this is a basic question.
We have a SQL 2000 SP3 server running on Windows 2003 SP1. We have a remote
site that connects to this server via a T1 line using a program that we
created called popss.
What happens is that the program takes a long time getting the data from the
server and we know that it's a bandwidth issue. What I would like to know
is there a way to install a toned down version of SQL something like desktop
on another Windows 2003 server or do we need the another full version of SQL
at that location so that the program can read from the local instance
instead of going over the pipe.
I am looking for a way to sync up the two SQL databases say at night this
way there we be no traffic over the pipe during the day.
Thank You
Adam RaffYou could use Transactional Replication and set its schedule as running once
at night. SQL Server Express Edition can be used as a Subscriber in a
Replication topology and it's free. However, Express Edition has its
limitations. (4GB db, 1 CPU, 1GB RAM)
http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx
You would make your current SQL Server as Publisher \ Distributor (consider
workload on your current server) and the other one would be the Subscriber.
So, your new SQL Server would be updated daily and your app would query your
local SQL Server directly.
Try this in a test environment first. If your system and app works without
any problem then you could apply it to your production system.
--
Ekrem Önsoy
"Adam Raff" <araff@.newsgroup.nospam> wrote in message
news:OZ7NvdW9HHA.4752@.TK2MSFTNGP04.phx.gbl...
> Good Day,
> I have a simple question on SQL 2000. Please note that I am no expert and
> this is a basic question.
> We have a SQL 2000 SP3 server running on Windows 2003 SP1. We have a
> remote site that connects to this server via a T1 line using a program
> that we created called popss.
> What happens is that the program takes a long time getting the data from
> the server and we know that it's a bandwidth issue. What I would like to
> know is there a way to install a toned down version of SQL something like
> desktop on another Windows 2003 server or do we need the another full
> version of SQL at that location so that the program can read from the
> local instance instead of going over the pipe.
> I am looking for a way to sync up the two SQL databases say at night this
> way there we be no traffic over the pipe during the day.
> Thank You
> Adam Raff
>|||Ekrem,
Thanks for your help. The size of the database is small about 500MB so that
is not an issue. My only other question on this is Does this go both ways.
Meaning when they copy to the SQL Express will it update the SQL server
later during the Replication time since the Express is setup as Subscriber?
Thanks again for your help
Adam Raff
"Ekrem Önsoy" <ekrem@.btegitim.com> wrote in message
news:11330C0D-7942-4968-BB9F-230F6FD3EA83@.microsoft.com...
> You could use Transactional Replication and set its schedule as running
> once at night. SQL Server Express Edition can be used as a Subscriber in a
> Replication topology and it's free. However, Express Edition has its
> limitations. (4GB db, 1 CPU, 1GB RAM)
> http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx
> You would make your current SQL Server as Publisher \ Distributor
> (consider workload on your current server) and the other one would be the
> Subscriber. So, your new SQL Server would be updated daily and your app
> would query your local SQL Server directly.
> Try this in a test environment first. If your system and app works without
> any problem then you could apply it to your production system.
> --
> Ekrem Önsoy
>
> "Adam Raff" <araff@.newsgroup.nospam> wrote in message
> news:OZ7NvdW9HHA.4752@.TK2MSFTNGP04.phx.gbl...
>> Good Day,
>> I have a simple question on SQL 2000. Please note that I am no expert
>> and this is a basic question.
>> We have a SQL 2000 SP3 server running on Windows 2003 SP1. We have a
>> remote site that connects to this server via a T1 line using a program
>> that we created called popss.
>> What happens is that the program takes a long time getting the data from
>> the server and we know that it's a bandwidth issue. What I would like to
>> know is there a way to install a toned down version of SQL something like
>> desktop on another Windows 2003 server or do we need the another full
>> version of SQL at that location so that the program can read from the
>> local instance instead of going over the pipe.
>> I am looking for a way to sync up the two SQL databases say at night this
>> way there we be no traffic over the pipe during the day.
>> Thank You
>> Adam Raff
>|||Dear Adam,
Thank you for posting here.
I would like to explain that the SQL Server 2000 does not support the
updatable Subscriptions for Transactional Replication and the SQL Server
2005 Express 2005 Edition can only be configured as the Subscriber. So, the
replication is done in only one way and the data written in the SQL Express
will not be transferred to the main SQL Server.
If your application "Popss" only reads the data from SQL Server, we can
choose to use Transactional Replication. If not, we can try the Merge
Replication so that the changes can be synchronized to the publisher.
For your reference, I have included some relevant articles below:
How Merge Replication Works
http://technet.microsoft.com/en-us/library/ms151329.aspx
How Transactional Replication Works
http://technet.microsoft.com/en-us/library/ms151706.aspx
If anything is unclear in my reply, please don't hesitate to let me know
and I will be glad to help.
Have a nice day!
Best regards,
Adams Qu, MCSE, MCDBA, MCTS
Microsoft Online Support
Microsoft Global Technical Support Center
Get Secure! - www.microsoft.com/security
=====================================================When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.
| From: "Adam Raff" <araff@.newsgroup.nospam>
| References: <OZ7NvdW9HHA.4752@.TK2MSFTNGP04.phx.gbl>
<11330C0D-7942-4968-BB9F-230F6FD3EA83@.microsoft.com>
| Subject: Re: Question on SQL
| Date: Wed, 12 Sep 2007 16:40:10 -0400
| Lines: 62
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
| X-RFC2646: Format=Flowed; Response
| Message-ID: <OyQZd0X9HHA.1212@.TK2MSFTNGP05.phx.gbl>
| Newsgroups: microsoft.public.sqlserver.server
| NNTP-Posting-Host: 208-39-138-189.isp.comcastbusiness.net 208.39.138.189
| Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP05.phx.gbl
| Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.sqlserver.server:25271
| X-Tomcat-NG: microsoft.public.sqlserver.server
|
| Ekrem,
|
| Thanks for your help. The size of the database is small about 500MB so
that
| is not an issue. My only other question on this is Does this go both
ways.
|
| Meaning when they copy to the SQL Express will it update the SQL server
| later during the Replication time since the Express is setup as
Subscriber?
|
| Thanks again for your help
| Adam Raff
|
|
|
| "Ekrem Önsoy" <ekrem@.btegitim.com> wrote in message
| news:11330C0D-7942-4968-BB9F-230F6FD3EA83@.microsoft.com...
| > You could use Transactional Replication and set its schedule as running
| > once at night. SQL Server Express Edition can be used as a Subscriber
in a
| > Replication topology and it's free. However, Express Edition has its
| > limitations. (4GB db, 1 CPU, 1GB RAM)
| >
| > http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx
| >
| > You would make your current SQL Server as Publisher \ Distributor
| > (consider workload on your current server) and the other one would be
the
| > Subscriber. So, your new SQL Server would be updated daily and your app
| > would query your local SQL Server directly.
| >
| > Try this in a test environment first. If your system and app works
without
| > any problem then you could apply it to your production system.
| >
| > --
| > Ekrem Önsoy
| >
| >
| >
| > "Adam Raff" <araff@.newsgroup.nospam> wrote in message
| > news:OZ7NvdW9HHA.4752@.TK2MSFTNGP04.phx.gbl...
| >> Good Day,
| >>
| >> I have a simple question on SQL 2000. Please note that I am no expert
| >> and this is a basic question.
| >>
| >> We have a SQL 2000 SP3 server running on Windows 2003 SP1. We have a
| >> remote site that connects to this server via a T1 line using a program
| >> that we created called popss.
| >>
| >> What happens is that the program takes a long time getting the data
from
| >> the server and we know that it's a bandwidth issue. What I would like
to
| >> know is there a way to install a toned down version of SQL something
like
| >> desktop on another Windows 2003 server or do we need the another full
| >> version of SQL at that location so that the program can read from the
| >> local instance instead of going over the pipe.
| >>
| >> I am looking for a way to sync up the two SQL databases say at night
this
| >> way there we be no traffic over the pipe during the day.
| >>
| >> Thank You
| >> Adam Raff
| >>
| >
|
|
||||Hi Adams,
If we upgrade to SQL 2005 lets say or the newer version of SQL 2007 will
this then work then?
Is the Express version limited in that it can never sync up with the full
version of SQL?
Thanks
Adam Raff
"Adams Qu [MSFT]" <v-adamqu@.online.microsoft.com> wrote in message
news:WwE9G5d9HHA.5532@.TK2MSFTNGHUB02.phx.gbl...
> Dear Adam,
> Thank you for posting here.
> I would like to explain that the SQL Server 2000 does not support the
> updatable Subscriptions for Transactional Replication and the SQL Server
> 2005 Express 2005 Edition can only be configured as the Subscriber. So,
> the
> replication is done in only one way and the data written in the SQL
> Express
> will not be transferred to the main SQL Server.
> If your application "Popss" only reads the data from SQL Server, we can
> choose to use Transactional Replication. If not, we can try the Merge
> Replication so that the changes can be synchronized to the publisher.
> For your reference, I have included some relevant articles below:
> How Merge Replication Works
> http://technet.microsoft.com/en-us/library/ms151329.aspx
> How Transactional Replication Works
> http://technet.microsoft.com/en-us/library/ms151706.aspx
> If anything is unclear in my reply, please don't hesitate to let me know
> and I will be glad to help.
> Have a nice day!
> Best regards,
> Adams Qu, MCSE, MCDBA, MCTS
> Microsoft Online Support
> Microsoft Global Technical Support Center
> Get Secure! - www.microsoft.com/security
> =====================================================> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> =====================================================> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> --
> | From: "Adam Raff" <araff@.newsgroup.nospam>
> | References: <OZ7NvdW9HHA.4752@.TK2MSFTNGP04.phx.gbl>
> <11330C0D-7942-4968-BB9F-230F6FD3EA83@.microsoft.com>
> | Subject: Re: Question on SQL
> | Date: Wed, 12 Sep 2007 16:40:10 -0400
> | Lines: 62
> | X-Priority: 3
> | X-MSMail-Priority: Normal
> | X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
> | X-RFC2646: Format=Flowed; Response
> | Message-ID: <OyQZd0X9HHA.1212@.TK2MSFTNGP05.phx.gbl>
> | Newsgroups: microsoft.public.sqlserver.server
> | NNTP-Posting-Host: 208-39-138-189.isp.comcastbusiness.net 208.39.138.189
> | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP05.phx.gbl
> | Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.sqlserver.server:25271
> | X-Tomcat-NG: microsoft.public.sqlserver.server
> |
> | Ekrem,
> |
> | Thanks for your help. The size of the database is small about 500MB so
> that
> | is not an issue. My only other question on this is Does this go both
> ways.
> |
> | Meaning when they copy to the SQL Express will it update the SQL server
> | later during the Replication time since the Express is setup as
> Subscriber?
> |
> | Thanks again for your help
> | Adam Raff
> |
> |
> |
> | "Ekrem Önsoy" <ekrem@.btegitim.com> wrote in message
> | news:11330C0D-7942-4968-BB9F-230F6FD3EA83@.microsoft.com...
> | > You could use Transactional Replication and set its schedule as
> running
> | > once at night. SQL Server Express Edition can be used as a Subscriber
> in a
> | > Replication topology and it's free. However, Express Edition has its
> | > limitations. (4GB db, 1 CPU, 1GB RAM)
> | >
> | > http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx
> | >
> | > You would make your current SQL Server as Publisher \ Distributor
> | > (consider workload on your current server) and the other one would be
> the
> | > Subscriber. So, your new SQL Server would be updated daily and your
> app
> | > would query your local SQL Server directly.
> | >
> | > Try this in a test environment first. If your system and app works
> without
> | > any problem then you could apply it to your production system.
> | >
> | > --
> | > Ekrem Önsoy
> | >
> | >
> | >
> | > "Adam Raff" <araff@.newsgroup.nospam> wrote in message
> | > news:OZ7NvdW9HHA.4752@.TK2MSFTNGP04.phx.gbl...
> | >> Good Day,
> | >>
> | >> I have a simple question on SQL 2000. Please note that I am no
> expert
> | >> and this is a basic question.
> | >>
> | >> We have a SQL 2000 SP3 server running on Windows 2003 SP1. We have a
> | >> remote site that connects to this server via a T1 line using a
> program
> | >> that we created called popss.
> | >>
> | >> What happens is that the program takes a long time getting the data
> from
> | >> the server and we know that it's a bandwidth issue. What I would
> like
> to
> | >> know is there a way to install a toned down version of SQL something
> like
> | >> desktop on another Windows 2003 server or do we need the another full
> | >> version of SQL at that location so that the program can read from the
> | >> local instance instead of going over the pipe.
> | >>
> | >> I am looking for a way to sync up the two SQL databases say at night
> this
> | >> way there we be no traffic over the pipe during the day.
> | >>
> | >> Thank You
> | >> Adam Raff
> | >>
> | >
> |
> |
> |
>|||Correction: There is no version 2007 of SQL Server. SQL Server 2008 is the
one that's going to be successor of SQL Server 2005.
If you want to transfer changes that you make in your second SQL Server to
be applied to your first SQL Server, then use Merge Replication. As you can
not use SQL Server Express Edition in a Updatable Subscriptions for
Transactional Replication topology, you may want to go with Merge
Replication. You'd be able to use Express Edition in a Transactional
Replication if you wanted to use your second SQL Server only for reporting
server purposes which means you would not want to transfer the updated
records from your second SQL Server to the First one.
Express Edition's limitation is just to be Subscriber in a Replication
Topology in this topic. It can not be a Publisher nor Distributor. But it
can be a Subscriber and for you situation can be used in a Merge Replication
topology.
Just give it a try Merge Replication on your test machine and see how it
works.
If you'd like to learn more about Transactional and Merge Replications, I
encourage you you to visit the links that Adams already mentioned.
>> How Merge Replication Works
>> http://technet.microsoft.com/en-us/library/ms151329.aspx
>> How Transactional Replication Works
>> http://technet.microsoft.com/en-us/library/ms151706.aspx
Ekrem Önsoy
"Adam Raff" <araff@.newsgroup.nospam> wrote in message
news:eVK6zng9HHA.1212@.TK2MSFTNGP05.phx.gbl...
> Hi Adams,
> If we upgrade to SQL 2005 lets say or the newer version of SQL 2007 will
> this then work then?
> Is the Express version limited in that it can never sync up with the full
> version of SQL?
> Thanks
> Adam Raff
>
> "Adams Qu [MSFT]" <v-adamqu@.online.microsoft.com> wrote in message
> news:WwE9G5d9HHA.5532@.TK2MSFTNGHUB02.phx.gbl...
>> Dear Adam,
>> Thank you for posting here.
>> I would like to explain that the SQL Server 2000 does not support the
>> updatable Subscriptions for Transactional Replication and the SQL Server
>> 2005 Express 2005 Edition can only be configured as the Subscriber. So,
>> the
>> replication is done in only one way and the data written in the SQL
>> Express
>> will not be transferred to the main SQL Server.
>> If your application "Popss" only reads the data from SQL Server, we can
>> choose to use Transactional Replication. If not, we can try the Merge
>> Replication so that the changes can be synchronized to the publisher.
>> For your reference, I have included some relevant articles below:
>> How Merge Replication Works
>> http://technet.microsoft.com/en-us/library/ms151329.aspx
>> How Transactional Replication Works
>> http://technet.microsoft.com/en-us/library/ms151706.aspx
>> If anything is unclear in my reply, please don't hesitate to let me know
>> and I will be glad to help.
>> Have a nice day!
>> Best regards,
>> Adams Qu, MCSE, MCDBA, MCTS
>> Microsoft Online Support
>> Microsoft Global Technical Support Center
>> Get Secure! - www.microsoft.com/security
>> =====================================================>> When responding to posts, please "Reply to Group" via your newsreader so
>> that others may learn and benefit from your issue.
>> =====================================================>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> --
>> | From: "Adam Raff" <araff@.newsgroup.nospam>
>> | References: <OZ7NvdW9HHA.4752@.TK2MSFTNGP04.phx.gbl>
>> <11330C0D-7942-4968-BB9F-230F6FD3EA83@.microsoft.com>
>> | Subject: Re: Question on SQL
>> | Date: Wed, 12 Sep 2007 16:40:10 -0400
>> | Lines: 62
>> | X-Priority: 3
>> | X-MSMail-Priority: Normal
>> | X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
>> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
>> | X-RFC2646: Format=Flowed; Response
>> | Message-ID: <OyQZd0X9HHA.1212@.TK2MSFTNGP05.phx.gbl>
>> | Newsgroups: microsoft.public.sqlserver.server
>> | NNTP-Posting-Host: 208-39-138-189.isp.comcastbusiness.net
>> 208.39.138.189
>> | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP05.phx.gbl
>> | Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.sqlserver.server:25271
>> | X-Tomcat-NG: microsoft.public.sqlserver.server
>> |
>> | Ekrem,
>> |
>> | Thanks for your help. The size of the database is small about 500MB so
>> that
>> | is not an issue. My only other question on this is Does this go both
>> ways.
>> |
>> | Meaning when they copy to the SQL Express will it update the SQL server
>> | later during the Replication time since the Express is setup as
>> Subscriber?
>> |
>> | Thanks again for your help
>> | Adam Raff
>> |
>> |
>> |
>> | "Ekrem Önsoy" <ekrem@.btegitim.com> wrote in message
>> | news:11330C0D-7942-4968-BB9F-230F6FD3EA83@.microsoft.com...
>> | > You could use Transactional Replication and set its schedule as
>> running
>> | > once at night. SQL Server Express Edition can be used as a Subscriber
>> in a
>> | > Replication topology and it's free. However, Express Edition has its
>> | > limitations. (4GB db, 1 CPU, 1GB RAM)
>> | >
>> | > http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx
>> | >
>> | > You would make your current SQL Server as Publisher \ Distributor
>> | > (consider workload on your current server) and the other one would be
>> the
>> | > Subscriber. So, your new SQL Server would be updated daily and your
>> app
>> | > would query your local SQL Server directly.
>> | >
>> | > Try this in a test environment first. If your system and app works
>> without
>> | > any problem then you could apply it to your production system.
>> | >
>> | > --
>> | > Ekrem Önsoy
>> | >
>> | >
>> | >
>> | > "Adam Raff" <araff@.newsgroup.nospam> wrote in message
>> | > news:OZ7NvdW9HHA.4752@.TK2MSFTNGP04.phx.gbl...
>> | >> Good Day,
>> | >>
>> | >> I have a simple question on SQL 2000. Please note that I am no
>> expert
>> | >> and this is a basic question.
>> | >>
>> | >> We have a SQL 2000 SP3 server running on Windows 2003 SP1. We have
>> a
>> | >> remote site that connects to this server via a T1 line using a
>> program
>> | >> that we created called popss.
>> | >>
>> | >> What happens is that the program takes a long time getting the data
>> from
>> | >> the server and we know that it's a bandwidth issue. What I would
>> like
>> to
>> | >> know is there a way to install a toned down version of SQL something
>> like
>> | >> desktop on another Windows 2003 server or do we need the another
>> full
>> | >> version of SQL at that location so that the program can read from
>> the
>> | >> local instance instead of going over the pipe.
>> | >>
>> | >> I am looking for a way to sync up the two SQL databases say at night
>> this
>> | >> way there we be no traffic over the pipe during the day.
>> | >>
>> | >> Thank You
>> | >> Adam Raff
>> | >>
>> | >
>> |
>> |
>> |
>|||Thank You both for explaining this to me. I will sit down to read the
articles to get an idea. Now that I know that it is possible to do with
what I have.
Thanks again for your help
Adam Raff
"Ekrem Önsoy" <ekrem@.btegitim.com> wrote in message
news:8E4680AF-987C-4999-90A3-33BF3B6D5953@.microsoft.com...
> Correction: There is no version 2007 of SQL Server. SQL Server 2008 is the
> one that's going to be successor of SQL Server 2005.
> If you want to transfer changes that you make in your second SQL Server to
> be applied to your first SQL Server, then use Merge Replication. As you
> can not use SQL Server Express Edition in a Updatable Subscriptions for
> Transactional Replication topology, you may want to go with Merge
> Replication. You'd be able to use Express Edition in a Transactional
> Replication if you wanted to use your second SQL Server only for reporting
> server purposes which means you would not want to transfer the updated
> records from your second SQL Server to the First one.
> Express Edition's limitation is just to be Subscriber in a Replication
> Topology in this topic. It can not be a Publisher nor Distributor. But it
> can be a Subscriber and for you situation can be used in a Merge
> Replication topology.
> Just give it a try Merge Replication on your test machine and see how it
> works.
> If you'd like to learn more about Transactional and Merge Replications, I
> encourage you you to visit the links that Adams already mentioned.
>> How Merge Replication Works
>> http://technet.microsoft.com/en-us/library/ms151329.aspx
>> How Transactional Replication Works
>> http://technet.microsoft.com/en-us/library/ms151706.aspx
>
> --
> Ekrem Önsoy
>
> "Adam Raff" <araff@.newsgroup.nospam> wrote in message
> news:eVK6zng9HHA.1212@.TK2MSFTNGP05.phx.gbl...
>> Hi Adams,
>> If we upgrade to SQL 2005 lets say or the newer version of SQL 2007 will
>> this then work then?
>> Is the Express version limited in that it can never sync up with the full
>> version of SQL?
>> Thanks
>> Adam Raff
>>
>> "Adams Qu [MSFT]" <v-adamqu@.online.microsoft.com> wrote in message
>> news:WwE9G5d9HHA.5532@.TK2MSFTNGHUB02.phx.gbl...
>> Dear Adam,
>> Thank you for posting here.
>> I would like to explain that the SQL Server 2000 does not support the
>> updatable Subscriptions for Transactional Replication and the SQL Server
>> 2005 Express 2005 Edition can only be configured as the Subscriber. So,
>> the
>> replication is done in only one way and the data written in the SQL
>> Express
>> will not be transferred to the main SQL Server.
>> If your application "Popss" only reads the data from SQL Server, we can
>> choose to use Transactional Replication. If not, we can try the Merge
>> Replication so that the changes can be synchronized to the publisher.
>> For your reference, I have included some relevant articles below:
>> How Merge Replication Works
>> http://technet.microsoft.com/en-us/library/ms151329.aspx
>> How Transactional Replication Works
>> http://technet.microsoft.com/en-us/library/ms151706.aspx
>> If anything is unclear in my reply, please don't hesitate to let me know
>> and I will be glad to help.
>> Have a nice day!
>> Best regards,
>> Adams Qu, MCSE, MCDBA, MCTS
>> Microsoft Online Support
>> Microsoft Global Technical Support Center
>> Get Secure! - www.microsoft.com/security
>> =====================================================>> When responding to posts, please "Reply to Group" via your newsreader so
>> that others may learn and benefit from your issue.
>> =====================================================>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>>
>> --
>> | From: "Adam Raff" <araff@.newsgroup.nospam>
>> | References: <OZ7NvdW9HHA.4752@.TK2MSFTNGP04.phx.gbl>
>> <11330C0D-7942-4968-BB9F-230F6FD3EA83@.microsoft.com>
>> | Subject: Re: Question on SQL
>> | Date: Wed, 12 Sep 2007 16:40:10 -0400
>> | Lines: 62
>> | X-Priority: 3
>> | X-MSMail-Priority: Normal
>> | X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
>> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
>> | X-RFC2646: Format=Flowed; Response
>> | Message-ID: <OyQZd0X9HHA.1212@.TK2MSFTNGP05.phx.gbl>
>> | Newsgroups: microsoft.public.sqlserver.server
>> | NNTP-Posting-Host: 208-39-138-189.isp.comcastbusiness.net
>> 208.39.138.189
>> | Path: TK2MSFTNGHUB02.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFTNGP05.phx.gbl
>> | Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.sqlserver.server:25271
>> | X-Tomcat-NG: microsoft.public.sqlserver.server
>> |
>> | Ekrem,
>> |
>> | Thanks for your help. The size of the database is small about 500MB
>> so
>> that
>> | is not an issue. My only other question on this is Does this go both
>> ways.
>> |
>> | Meaning when they copy to the SQL Express will it update the SQL
>> server
>> | later during the Replication time since the Express is setup as
>> Subscriber?
>> |
>> | Thanks again for your help
>> | Adam Raff
>> |
>> |
>> |
>> | "Ekrem Önsoy" <ekrem@.btegitim.com> wrote in message
>> | news:11330C0D-7942-4968-BB9F-230F6FD3EA83@.microsoft.com...
>> | > You could use Transactional Replication and set its schedule as
>> running
>> | > once at night. SQL Server Express Edition can be used as a
>> Subscriber
>> in a
>> | > Replication topology and it's free. However, Express Edition has its
>> | > limitations. (4GB db, 1 CPU, 1GB RAM)
>> | >
>> | > http://www.microsoft.com/sql/prodinfo/features/compare-features.mspx
>> | >
>> | > You would make your current SQL Server as Publisher \ Distributor
>> | > (consider workload on your current server) and the other one would
>> be
>> the
>> | > Subscriber. So, your new SQL Server would be updated daily and your
>> app
>> | > would query your local SQL Server directly.
>> | >
>> | > Try this in a test environment first. If your system and app works
>> without
>> | > any problem then you could apply it to your production system.
>> | >
>> | > --
>> | > Ekrem Önsoy
>> | >
>> | >
>> | >
>> | > "Adam Raff" <araff@.newsgroup.nospam> wrote in message
>> | > news:OZ7NvdW9HHA.4752@.TK2MSFTNGP04.phx.gbl...
>> | >> Good Day,
>> | >>
>> | >> I have a simple question on SQL 2000. Please note that I am no
>> expert
>> | >> and this is a basic question.
>> | >>
>> | >> We have a SQL 2000 SP3 server running on Windows 2003 SP1. We have
>> a
>> | >> remote site that connects to this server via a T1 line using a
>> program
>> | >> that we created called popss.
>> | >>
>> | >> What happens is that the program takes a long time getting the data
>> from
>> | >> the server and we know that it's a bandwidth issue. What I would
>> like
>> to
>> | >> know is there a way to install a toned down version of SQL
>> something
>> like
>> | >> desktop on another Windows 2003 server or do we need the another
>> full
>> | >> version of SQL at that location so that the program can read from
>> the
>> | >> local instance instead of going over the pipe.
>> | >>
>> | >> I am looking for a way to sync up the two SQL databases say at
>> night
>> this
>> | >> way there we be no traffic over the pipe during the day.
>> | >>
>> | >> Thank You
>> | >> Adam Raff
>> | >>
>> | >
>> |
>> |
>> |
>>
>|||Dear Adam,
Thank you for your response.
If you have any other questions or concerns, please do not hesitate to
contact me. It is always my pleasure to be of assistance.
Have a nice day!
Best regards,
Adams Qu, MCSE, MCDBA, MCTS
Microsoft Online Support
Microsoft Global Technical Support Center
Get Secure! - www.microsoft.com/security
=====================================================When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=====================================================This posting is provided "AS IS" with no warranties, and confers no rights.

Monday, February 20, 2012

question on a stored procedure...

Hi all,
I have a basic question with a stored procedure I'm using. The procedure is as follows:
CREATE PROCEDURE CheckUserLogin(@.Login nvarchar(50), @.Password nvarchar(50)) AS
DECLARE @.UserId varchar(50)
DECLARE @.SchoolId int
DECLARE @.title varchar(50)

IF EXISTS(SELECT Login, Pass FROM Users WHERELogin=@.Login and Pass=@.Password)
BEGIN
SELECT UserId, SchoolId, title FROM Users WHERELogin=@.Login andPass=@.Password
END
ELSE
BEGIN
SELECT @.UserId ='InvalidLogin', @.SchoolId = 0, @.title = 'Applicant'
END
GO
--*******************************************************************--
The thing is that when I read the results, the Else part from the procedure doesn't return anything, so I'm assuming how I've declared the variables or the way I'm selecting them is wrong because if the password and login are correct (this is the first if statement), then when I read the results, I get to where I'm supposed to; however, if the Login and password are incorrect, then I'm supposed to return the Else part...but it doesn't return anything
I have the following when trying to check the userLogin and password

Dim resultAs SqlDataReader

result = CheckUserLoginCmd.ExecuteReader

While result.Read..
...
but I never go into the While loop if the login and password are incorrect, but I do go into the while loop if login and password are correct, and I get the expected behavior. Thanks for your help,

You'd have to use OUTPUT parameters to retrieve that data you are capturing in those @.variables. Try it like this instead:
CREATE PROCEDURE CheckUserLogin(@.Login nvarchar(50), @.Password nvarchar(50)) AS
IF EXISTS(SELECT Login, Pass FROM Users WHERELogin=@.Login and Pass=@.Password)
BEGIN
SELECT UserId, SchoolId, title FROM Users WHERELogin=@.Login andPass=@.Password
END
ELSE
BEGIN
SELECT UserId ='InvalidLogin', SchoolId = 0, title = 'Applicant'
END
GO
|||

Hi,

Thanks for your reply. I actually already tried it like that, but it gave me an error:

Input string was not in a correct format.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.FormatException: Input string was not in a correct format.
Source Error:

Line 130: With userLine 131: If Not IsDBNull(result("UserId")) ThenLine 132: .userId = CType(result("UserId"), String)Line 133: End IfLine 134: If Not IsDBNull(result("SchoolId")) Then

I thought this was because of the way I was returning the result, but maybe the error is something else?...If you have any idea, please let me know. Thanks again.