Showing posts with label alli. Show all posts
Showing posts with label alli. Show all posts

Tuesday, March 27, 2012

Getting the error "XML stored procedures are not supported in fibers mode"

Hello All
I am getting the error "XML stored procedures are not supported in fibers
mode", when I try to run the example xmlsql given in the SQL books online...
I have changed my "lightweight pooling option to 0", using sp_configure.
I have restarted the server after this.
sp_configure,'show advanced options', 1 will show the lightweight pooling
as 0
But I am still getting the error.
I am using Sql 2000 on windows 2003
Please help. thanks in advance
-rahul
Did you execute the reconfigure command?
This is needed to make the configuration change active.
Best regards
Michael
"RP" <rahulpidaparti@.yahoo.com> wrote in message
news:ODSgBqU2EHA.3244@.TK2MSFTNGP11.phx.gbl...
> Hello All
> I am getting the error "XML stored procedures are not supported in fibers
> mode", when I try to run the example xmlsql given in the SQL books
> online...
> I have changed my "lightweight pooling option to 0", using sp_configure.
> I have restarted the server after this.
> sp_configure,'show advanced options', 1 will show the lightweight
> pooling
> as 0
> But I am still getting the error.
> I am using Sql 2000 on windows 2003
> Please help. thanks in advance
> -rahul
>

Monday, March 26, 2012

Getting started with Sql Server 2005....Create Database

Hi allI'm a newbie with Visual studio 2005 .Recently i installed it ,AFAIK sqlServer 2005also is shiped with vs2005.after installing vs2005 i have the following entries in my StartMenu/All Programms/1) Microsoft Sql Server 2005Configuration Tools sql Server Configuration Manager Sql Server Error and usage Reporting SQL Server Surface Area Configuration2) Microsoft Visual studio 2005 .... ......Apparently there isn't any ENTERPRISE MANAGER and query analyzer.?By the way in Visual studio IDE i noticed "Server Explorer" nexed to "Solution Explorer"but i didn't find any Database entry or "Create New Database" or some thing like this.!!!Could any one help me.? i want to Create Database, Tables,...Thanks in advance.Regards.

You're looking for Management Studio Express. Start with:

http://msdn.microsoft.com/vstudio/express/sql/compare/default.aspx

Jeff

|||

ZarrinPour:

Hi all I'm a newbie with Visual studio 2005 .Recently i installed it ,AFAIK sqlServer 2005 also is shiped with vs2005.after installing vs2005 i have the following entries in my StartMenu/All Programms/ 1) Microsoft Sql Server 2005 Configuration Tools sql Server Configuration Manager Sql Server Error and usage Reporting SQL Server Surface Area Configuration 2) Microsoft Visual studio 2005 .... ...... Apparently there isn't any ENTERPRISE MANAGER and query analyzer.? By the way in Visual studio IDE i noticed "Server Explorer" nexed to "Solution Explorer" but i didn't find any Database entry or "Create New Database" or some thing like this.!!! Could any one help me.? i want to Create Database, Tables,... Thanks in advance. Regards.

That depends on the edition of VS2005 if you have standard you can use the Advanced version of Express from the link below however profesional comes with the developer edition which means you need to copy the contents of your CD/DVD to your hard drive and rerun setup and choose add components or repair and add the management tools that gives you Management Studio. Hope this helps.

http://msdn.microsoft.com/vstudio/express/sql/download/

sql

Friday, March 23, 2012

getting sql query in c# code

Dear All

I am a beginner and looking for some help. I have a database with just one column (some names). That is the primary key aswell. Because I want the names to be unique.

I used a grid view control to display the data and included the insert functionality in the grid view by using some code and the part of the code that does the insert is

1public static void Insert(Categories category)2 {3string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;4using (IDbConnection cn =new SqlConnection(connectionString))5 {6 cn.Open();78 IDbCommand cmd =new SqlCommand();910 cmd.CommandText ="INSERT INTO Categories (CategoryName) VALUES " +11"('" + category.CategoryName +"')";1213 cmd.Connection = cn;14 cmd.ExecuteNonQuery();15 }16 }

Question: when someone tried to enter a new name which already exists in the database it throws an error page which is what I want but is there a way to be able to display the user a message sayin g that he/she has entered a name that already exists and hence they need to try a different name? instead of the ugly error page?

Thank you in advance,

Prasad.

Yes. You need to add a Try... Catch block to catch the exception, and handle it:

public static void Insert(Categories category)
{
string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (SqlConnection cn = new SqlConnection(connectionString))
{
try
{
SqlCommand cmd = new SqlCommand();

cmd.CommandText = "INSERT INTO Categories (CategoryName) VALUES (@.CategoryName)
cmd.Parameters.AddWithValue("@.CategoryName", category.CategoryName);

cmd.Connection = cn;
cn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Label1.Text = "That value already exists. Please try another.";
}
}

I have also changed your code to use parameters, which is best practice. This means you don't have to worry about people entering words with apostrophes causing errors, or Sql Injection.

Also, you should ideally query the database to see if the name exists prior to attempting the insert. Throwing exceptions is expensive on the server.

|||

thank you. Hmm..I knew the try catch solution but I was just thinking...that the try catch would catch any exception that came from insert right?

For example if there was some other strange problem in doing the insert, it would still say "name already exists try another name!" which will be kind of strange.

lastly, Thank you for the modified code, I am a newbie and still learning, thanks for the tip! However, when I compile your code, it says

System.Data.IDataParameterCollection' does not contain a definition for 'AddWithValue'

can you please tell me how to check if that name already exists? some code would help please.

something like doing a count and on that particular name and see if count is > 1?


|||

Are you using version 1.1? If so, change that to cmd.Parameters.Add(...). AddWithValue was added to version 2.0.

Instead of hardcoding the error message, you could also use ex.Message

Label1.Text = ex.Message;

However, sometimes the error message might be too obscure for the user to understand. The most likely error will result from an attempt to insert a duplicate value. That's why I recommended that you select the value of the submitted entry first to see if it exists. If it does, abort the insert and show a message. If not, let the insert run.

|||

my mistake, I had not replaced the IDBcommand with SqlCommand

ok now coming to the second problem,

I donot know how to count the number of times the name appears in the database!

can you get me started with the code!

|||

The SQL is "Select Count(*) AS TheCount From Categories Where CategoryName = @.CategoryName"

int theCount = (int)cmd.ExecuteScalar();

Then, if theCount is more than 0, that means there is a least one row already in the database. If it doesn't exist, the value of theCount will be 0.

|||

"For example if there was some other strange problem in doing the insert, it would still say "name already exists try another name!" which will be kind of strange."

That is because you have this column as the Primary Key. The Primary Key has to be unique (ie No Duplicates)

|||

You should use a stored procedure for this kind of operations. There you can first write the code for checking for duplicate values like below.

ifexists (select 1from Categorieswhere CategoryName = @.categoryName)beginraiserror ('The provided category name already exists' , 16 , 1 )with nowaitreturnendelsebegininsert Categories (CategoryName)values (@.categoryname)end

This is just a snap of what can be included in the SP. Look at the line where raiserror function is used. You'll still have to write the SP execution code in a try catch block, but you're sure that the error stating "The provided category name already exists" is generated by your SP and all other errors are because of other problems.

For a general help regarding executing SP from code visithttp://forums.asp.net/t/1165758.aspx.

Hope this will help.