Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Thursday, March 8, 2012

"Prepare" in SQL Server through ODBC/ADO

Hi,
When using an interface like ADO or ODBC, there is a call named
"Prepare" which supposedly sent the statement to the server which in
turn should parse it, save the query plan and return a handle to the
client so subquent calls just refer to this handle/id and get faster
execution in batches... is this correct?
Well, my question is, when this Prepare or Parse is done, is there any
physical check being performed by SQL Server ? I mean, does it check
the column names, table existance, etc, or does it just check pure
syntax ?According to the ODBC 3.0 SDK, a SQLPrepare call to an ODBC driver sends the
statement to the data source for preparation and stores the returned access
plan identifier for later execution; or returns any errors including
SQLSTATE 42000 (Syntax error or access violation) and SQLSTATE 42S02 (Base
table or view not found). It also notes that some drivers do not return
errors after SQLPrepare is called, but rather when the statement is executed
later. So "SQLPrepare might appear to have succeeded when in fact it has
failed."
It would seem that you can't rely on a SQLPrepare call to return errors,
since not all drivers support that functionality via SQLPrepare.
Thanks,
Mike C.
<craigkenisston@.hotmail.com> wrote in message
news:1109726936.969442.224550@.o13g2000cwo.googlegroups.com...
> Hi,
> When using an interface like ADO or ODBC, there is a call named
> "Prepare" which supposedly sent the statement to the server which in
> turn should parse it, save the query plan and return a handle to the
> client so subquent calls just refer to this handle/id and get faster
> execution in batches... is this correct?
> Well, my question is, when this Prepare or Parse is done, is there any
> physical check being performed by SQL Server ? I mean, does it check
> the column names, table existance, etc, or does it just check pure
> syntax ?
>|||Thank you !!

Saturday, February 25, 2012

"No Resultset produced" when using temp tables in stored proc

I am using microsofts jdbc driver and I am trying to call a stored
procedure to get a resultset from SQL Server.
Usually this works fine when I select something from an ordinary table
but when I am involving a temp table in the final select statement I
do not get any resultset in return?
Lars wrote:

> I am using microsofts jdbc driver and I am trying to call a stored
> procedure to get a resultset from SQL Server.
> Usually this works fine when I select something from an ordinary table
> but when I am involving a temp table in the final select statement I
> do not get any resultset in return?
I believe the result set *does* come back, but your other stuff in the
procedure before the final select will also be returning update counts etc,
so you need to loop to handle all the update counts as well, before
getResultSet() will find the returned data.
Joe Weinstein at BEA

Sunday, February 19, 2012

"INSERT INTO" - Question

Hello,

if I have a row full of Data, lets call it Row "A". Now i have the "Insert Into" Command in my Application. So, when the User executes the Command again, will it update Row "A" or will it produce just a double?

This is important for my further Work with SQL.

I am using SQL Server 2006 Express or something like this. The Table in which Row "A" is has no primary key!

Greetz,

Eroli

Unless you have constraints/triggers or your INSERT violates the defaults/constraints, it will add a NEW ROW to the table irrespective of the existing data.

|||

Hi,

but when i put it all into a for-command like this one

for(int i = 0; i != 5;i++)

{

//All the Commands

}

I get only one row.

So, whats right now?

Greetz,

Eroli

|||Depends on what the commands are. Post all the relevant code and that might help.|||

System.Data.SqlClient.SqlCommand SqlCommand = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlConnection SqlConnection = new System.Data.SqlClient.SqlConnection();
SqlConnection.ConnectionString = (string)System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand.Connection = SqlConnection;
SqlCommand.CommandText = "INSERT INTO UsersTable([User], [FirstStart], [Commercial], [Name], [MailAddresse], [Addresse], [Addresse2], [Location], [PostCode], [Country], [PhoneNumber], [PhoneNumber2], [Sex], [ShowLastBoughts], [StartPage], [Notifications], [RemainingTime], [HomepageUrl], [Employees], [Owner], [Evaluations]) VALUES (@.User,@.FirstStart,@.Commercial, @.Name,@.MailAddresse,@.Addresse,@.Addresse2,@.Location,@.PostCode,@.Country,@.PhoneNumber,@.PhoneNumber2,@.Sex,@.ShowLastBoughts,@.StartPage,@.Notifications,@.RemainingTime,@.HomepageUrl,@.Employees,@.Owner,@.Evaluations)";
SqlCommand.Parameters.AddWithValue("@.User", Context.User.Identity.Name);
SqlCommand.Parameters.AddWithValue("@.FirstStart", -1);
SqlCommand.Parameters.AddWithValue("@.Commercial", -1);
SqlCommand.Parameters.AddWithValue("@.Name", "");
SqlCommand.Parameters.AddWithValue("@.MailAddresse", "");
SqlCommand.Parameters.AddWithValue("@.Addresse", "");
SqlCommand.Parameters.AddWithValue("@.Addresse2", "");
SqlCommand.Parameters.AddWithValue("@.Location", "");
SqlCommand.Parameters.AddWithValue("@.PostCode", -1);
SqlCommand.Parameters.AddWithValue("@.Country", "");
SqlCommand.Parameters.AddWithValue("@.PhoneNumber", -1);
SqlCommand.Parameters.AddWithValue("@.PhoneNumber2", -1);
SqlCommand.Parameters.AddWithValue("@.Sex", "");
SqlCommand.Parameters.AddWithValue("@.ShowLastBoughts", "");
SqlCommand.Parameters.AddWithValue("@.StartPage", -1);
SqlCommand.Parameters.AddWithValue("@.Notifications", -1);
SqlCommand.Parameters.AddWithValue("@.RemainingTime", -1);
SqlCommand.Parameters.AddWithValue("@.HomepageUrl", "");
SqlCommand.Parameters.AddWithValue("@.Employees", -1);
SqlCommand.Parameters.AddWithValue("@.Owner", "");
SqlCommand.Parameters.AddWithValue("@.Evaluations", "");
SqlConnection.Open();
SqlCommand.ExecuteNonQuery();
SqlConnection.Close();
SqlConnection.Dispose();

I've got only one Row.

|||

(1) Do you have any constraints/triggers on the table?

(2) Are you changing the values of the parameters for each loop or are youe xpecting to insert 5 rows with same values?

|||

The User Column will be everytime the same, but maybe some other colums will change.

Is the UPDATE-Command better? When yes, so how can i use this?

Im confused, because i have now more rows when i tried my application again. Seems your are right.

|||You need to explain more clearly what you are trying to do and what you intend to do. INSERT and UPDATE are 2 different commands that accomplish 2 different things. so there's no question of one "better" over another. You need to use either one depending on what how application needs to behave. Simply, INSERT inserts data into the table (meaning rows will increase), UPDATE updates te existing data (and how many rows affected depends on the WHERE condition in the query).|||

First my Application should create one row for one user. This can be done by using the INSERT Command, or not?

Then, when the user changes his data, it have to be updated. Here the UPDATE-Command should be useful, should'nt it?

|||

Eroli:

First my Application should create one row for one user. This can be done by using the INSERT Command, or not?

Yes.

Eroli:

Then, when the user changes his data, it have to be updated. Here the UPDATE-Command should be useful, should'nt it?

Yes. You need to do put your logic accordingly.

|||Ok, thanks for your advice!|||

Ok, i changed my Commands.

This is my UPDATE Command:

System.Data.SqlClient.SqlCommand SqlCommand = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlConnection SqlConnection = new System.Data.SqlClient.SqlConnection();
SqlConnection.ConnectionString = (string)System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand.Connection = SqlConnection;
SqlCommand.CommandText = "UPDATE UsersTable SET FirstStart=@.FirstStart,Commercial=@.Commercial,Name=@.Name,MailAddress=@.MailAddress,Address=@.Address,Address2=@.Address2,Location=@.Location,PostCode=@.PostCode,Country=@.Country,PhoneNumber=@.PhoneNumber,PhoneNumber2=@.PhoneNumber2,Sex=@.Sex WHERE User=@.User;";
SqlCommand.Parameters.AddWithValue("@.User", Context.User.Identity.Name);
SqlCommand.Parameters.AddWithValue("@.FirstStart", 0);
if (AccountTypeDropDownList.SelectedIndex == 0)
SqlCommand.Parameters.AddWithValue("@.Commercial", 0);
else if (AccountTypeDropDownList.SelectedIndex == 1)
SqlCommand.Parameters.AddWithValue("@.Commercial", 1);
SqlCommand.Parameters.AddWithValue("@.Name", NameTextBox.Text);
SqlCommand.Parameters.AddWithValue("@.MailAddress", EmailTextBox.Text);
SqlCommand.Parameters.AddWithValue("@.Address", AddressTextBox1.Text);
SqlCommand.Parameters.AddWithValue("@.Address2", AddressTextBox2.Text);
SqlCommand.Parameters.AddWithValue("@.Location", LocationTextBox.Text);
SqlCommand.Parameters.AddWithValue("@.PostCode", Convert.ToInt32(PostCodeTextBox.Text));
SqlCommand.Parameters.AddWithValue("@.Country", CountryTextBox.Text);
SqlCommand.Parameters.AddWithValue("@.PhoneNumber", PhoneNumberTextBox1.Text);
SqlCommand.Parameters.AddWithValue("@.PhoneNumber2", PhoneNumberTextBox2.Text);
switch (SexDropDownList.SelectedIndex)
{
case 0:
SqlCommand.Parameters.AddWithValue("@.Sex", -1);
break;

case 1:
SqlCommand.Parameters.AddWithValue("@.Sex", 0);
break;

case 2:
SqlCommand.Parameters.AddWithValue("@.Sex", 1);
break;
}
SqlConnection.Open();
SqlCommand.ExecuteNonQuery();
SqlConnection.Close();
SqlConnection.Dispose();</p><p>

It is in an ASP.NET Webapplication in C#! I get no failure, but nothing gets updated...

The obversely Row is filled with Dummy-Values before starting this Command.(MS SQL Server 2005 Express or so)

Greetz,

Eroli

|||

I hope this looks better...

System.Data.SqlClient.SqlCommand SqlCommand = new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlConnection SqlConnection = new System.Data.SqlClient.SqlConnection();
SqlConnection.ConnectionString = (string)System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand.Connection = SqlConnection;
SqlCommand.CommandText = "UPDATE UsersTable SET FirstStart=@.FirstStart,Commercial=@.Commercial,Name=@.Name,MailAddress=@.MailAddress,Address=@.Address,Address2=@.Address2,Location=@.Location,PostCode=@.PostCode,Country=@.Country,PhoneNumber=@.PhoneNumber,PhoneNumber2=@.PhoneNumber2,Sex=@.Sex WHERE User=@.User;";
SqlCommand.Parameters.AddWithValue("@.User", Context.User.Identity.Name);
SqlCommand.Parameters.AddWithValue("@.FirstStart", 0);
if (AccountTypeDropDownList.SelectedIndex == 0)
SqlCommand.Parameters.AddWithValue("@.Commercial", 0);
else if (AccountTypeDropDownList.SelectedIndex == 1)
SqlCommand.Parameters.AddWithValue("@.Commercial", 1);
SqlCommand.Parameters.AddWithValue("@.Name", NameTextBox.Text);
SqlCommand.Parameters.AddWithValue("@.MailAddress", EmailTextBox.Text);
SqlCommand.Parameters.AddWithValue("@.Address", AddressTextBox1.Text);
SqlCommand.Parameters.AddWithValue("@.Address2", AddressTextBox2.Text);
SqlCommand.Parameters.AddWithValue("@.Location", LocationTextBox.Text);
SqlCommand.Parameters.AddWithValue("@.PostCode", Convert.ToInt32(PostCodeTextBox.Text));
SqlCommand.Parameters.AddWithValue("@.Country", CountryTextBox.Text);
SqlCommand.Parameters.AddWithValue("@.PhoneNumber", PhoneNumberTextBox1.Text);
SqlCommand.Parameters.AddWithValue("@.PhoneNumber2", PhoneNumberTextBox2.Text);
switch (SexDropDownList.SelectedIndex)
{
case 0:
SqlCommand.Parameters.AddWithValue("@.Sex", -1);
break;

case 1:
SqlCommand.Parameters.AddWithValue("@.Sex", 0);
break;

case 2:
SqlCommand.Parameters.AddWithValue("@.Sex", 1);
break;
}
SqlConnection.Open();
SqlCommand.ExecuteNonQuery();
SqlConnection.Close();
SqlConnection.Dispose();

|||

Ok, i solved it: I have just forgotten to put the [ ] round my Columns.

But there is another Problem: THe Condition does not work, because the User Column is no Identify-Column. How to solve this?

|||I did not understand your question. Can you rephrase?

Thursday, February 16, 2012

"General network error. Check your network documentation." After Detach

Hello.
In our application we have to detach a database using a call from our
C# application. The problem is that after that we get random "General
Network Error" messages afterwards. This is all in a local call, both
the application server and the SqlServer are on the same machine.
I read about the Pooling = False switch but this is not an option for
us because this could have major repercusions on the rest of our
application.
Does anyone know how to get rid of this error without using the Pooling
= False?
Using .NET 1.1 and SqlServer 2000
ThanksAre you saying that you are killing database connections before the detach
and that causes the issues with your pooled connections? Is the detached
database specified as the 'Initial Catalog' specification in your connection
string?
If either or both are the case, I suggest you specify a different database
as the 'Initial Catalog' and change the database context to a different
database before closing the connection. That way, the polled connection can
remain open for reuse after the detach.
--
Hope this helps.
Dan Guzman
SQL Server MVP
<escristian@.hotmail.com> wrote in message
news:1148589276.174672.171190@.y43g2000cwc.googlegroups.com...
> Hello.
> In our application we have to detach a database using a call from our
> C# application. The problem is that after that we get random "General
> Network Error" messages afterwards. This is all in a local call, both
> the application server and the SqlServer are on the same machine.
> I read about the Pooling = False switch but this is not an option for
> us because this could have major repercusions on the rest of our
> application.
> Does anyone know how to get rid of this error without using the Pooling
> = False?
> Using .NET 1.1 and SqlServer 2000
> Thanks
>|||The architecture I'm working with basically creates a new SqlConnection
everytime we make a call to the SqlService object (only way to access
database). To detach the database I put the database to offline mode
and then detach, here's the sql syntax I use:
USE master ALTER DATABASE <<dbName>> SET OFFLINE WITH ROLLBACK
IMMEDIATE
USE master EXEC sp_detach_db '<<dbName>>', 'true'
So our architecture will create a new connection before the 1st line of
sql, destroy that connection and then create another connection before
the 2nd call.
I will start reading on the connection pooling cause that seems to be
the cause of all these problems.
Thanks for your help|||Have you tried changing the database context to another database (e.g.
master) before closing the connection as I previously suggested? That way,
pooled connections won't be killed when you execute the ALTER
DATABASE...ROLLBACK.
--
Hope this helps.
Dan Guzman
SQL Server MVP
<escristian@.hotmail.com> wrote in message
news:1148654269.887685.237720@.i39g2000cwa.googlegroups.com...
> The architecture I'm working with basically creates a new SqlConnection
> everytime we make a call to the SqlService object (only way to access
> database). To detach the database I put the database to offline mode
> and then detach, here's the sql syntax I use:
> USE master ALTER DATABASE <<dbName>> SET OFFLINE WITH ROLLBACK
> IMMEDIATE
> USE master EXEC sp_detach_db '<<dbName>>', 'true'
> So our architecture will create a new connection before the 1st line of
> sql, destroy that connection and then create another connection before
> the 2nd call.
> I will start reading on the connection pooling cause that seems to be
> the cause of all these problems.
> Thanks for your help
>

"General network error. Check your network documentation." After Detach

Hello.
In our application we have to detach a database using a call from our
C# application. The problem is that after that we get random "General
Network Error" messages afterwards. This is all in a local call, both
the application server and the SqlServer are on the same machine.
I read about the Pooling = False switch but this is not an option for
us because this could have major repercusions on the rest of our
application.
Does anyone know how to get rid of this error without using the Pooling
= False?
Using .NET 1.1 and SqlServer 2000
ThanksAre you saying that you are killing database connections before the detach
and that causes the issues with your pooled connections? Is the detached
database specified as the 'Initial Catalog' specification in your connection
string?
If either or both are the case, I suggest you specify a different database
as the 'Initial Catalog' and change the database context to a different
database before closing the connection. That way, the polled connection can
remain open for reuse after the detach.
Hope this helps.
Dan Guzman
SQL Server MVP
<escristian@.hotmail.com> wrote in message
news:1148589276.174672.171190@.y43g2000cwc.googlegroups.com...
> Hello.
> In our application we have to detach a database using a call from our
> C# application. The problem is that after that we get random "General
> Network Error" messages afterwards. This is all in a local call, both
> the application server and the SqlServer are on the same machine.
> I read about the Pooling = False switch but this is not an option for
> us because this could have major repercusions on the rest of our
> application.
> Does anyone know how to get rid of this error without using the Pooling
> = False?
> Using .NET 1.1 and SqlServer 2000
> Thanks
>

Friday, January 27, 2012

Reporting Services Error !

I have installed SQL Server Reporting Services and I recieve the following error when I attempt to call the reportserver from the URL.

"Server Application Unavailable
The web application you are attempting to access on this web server is currently unavailable. Please hit the 'Refresh' button in your web browser to retry your request.

Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur. "

In the event log, the following error is recorded..."

"aspnet_wp.exe could not be started. The error code for the failure is 80004005. This error can be caused when the worker process account has insufficient rights to read the .NET Framework files. Please ensure that the .NET Framework is correctly installed and that the ACLs on the installation directory allow access to the configured account. "

I have ran "aspnet_regiis -i" after installing reporting services...
I have validated that ASPNET has the correct permissions...
I have validated that ASPNET user account has not been lockedout...
I have restarted the Report Server service...
I have restarted the IIS service...
I even have restarted the server...

Does anyone have any other ideas that may help! Thank you in advance.Try this url it is permissions related. Hope this helps.

http://support.microsoft.com/default.aspx?scid=kb;en-us;315158

Kind regards,
Gift Peddie|||My server is not a domain controller. The instructions on the link that you provided addresses the issue if it is a domain controller.

I did check my machine.config file and the <processModel> contains:

userName="machine"
password="AutoGenerate"

Why wouldn't this work for a non-domain controller server?|||Also, by the way, I have installed the .Net 1.1 hot fix|||I am sorry I did not ask you if you installed the Reporting Services and SQL Server with Service accounts because when SQL Server is installed in a Networked box is it good practice to use Service accounts so you will not get all the permissions related errors. Hope this helps.

Kind regards,
Gift Peddie|||I am using the domain service account. Would I need to change the machine.config file to different settings other than below?

userName="machine"
password="AutoGenerate"

Also, when I attempt to run rsactivate, I recieve the following error:
Failure parsing the config file.
Invalid URI: The host name could not be parsed.

The config file that it is referring to is the rsreportserver.config.|||Reporting Service applications are run through IIS so the username should be the Asp.net worker process account which is different from the service account used to install Reproting Service. You may also need to give Asp.net account full permissions to the Reporting application root folder. Hope this helps.

Kind regards,
Gift Peddie