Showing posts with label project. Show all posts
Showing posts with label project. Show all posts

Wednesday, March 28, 2012

Read, write and update xml data type.

Hi All,

I would like to learn about xml data type of sql server 2005. I am using c# to develop a project that will use sql server express as a database. What I want to accomplish in my project is to serialize an object and save into a field with xml data type. Also I want to have same functionality in other way around. Retrieve this xml representation of the object, Deserialize it so get the saved object back into application.

I would be happy If you can provide me some code which shows how to accomplish this task or some links that directs me to the appropriate docs.

Thanks in advance.

There is lots of material on MSDN, there is a section about the xml data type with subsections about the methods of the xml data type (i.e. query, value, exist, modify, nodes) and the XML DML (XML data modification language).|||

Hi Martin,

Thanks for the reply and links. I haven't gone through the links you sent completly but I think the subject I typed here is misleading so let me explain a bit more, the difficulty I have. . I have no problem with creating a table with an xml type field. I believe by reading the links you have sent I can perform insert, update and delete functions. My difficulty starts just after the seriliazation of an object or just before the deserialization of the xml data I read from xml field. Both serialize and deserialize methods trys to write/read to/from a file or a stream. All I want is to hold this xml in a data structure where I can use it at the time of serialization or deserialization.

The original situaltion:

I have a form to be filled out by the users of my application. Since there are so many fields of data in this form I dont want to create a table with somany fields. So I am planing to hold info entered by user in an xml field. (and ofcourse I should be able to read the data back from this xml field and display in the app)

Thanks.

|||

Got it worked Smile

I used string/TextWriter and string/TextReader combinations and worked fine. Thanks.

FlatWhite

|||

Hi FlatWhite

I would like to do the same thing you are doing. Could you provide some code snippets for me on how to do it?

Thanks

|||

Well I am neither SQL nor C# expert so you can use my code at your own risk J

First of all I am assuming that you have an SQL database table which has ID and XML fields and also you have InsertObj and SelectObj stored procedures.

TABLE : ObjectTable

ObjID-int-identity

ObjXML-XML

SPs : InsertObj

SelectObj

Code Snippet

CREATE PROCEDURE InsertObj

@.ObjXML xml

AS

BEGIN

INSERT INTO ObjectTable (ObjXML)

VALUES (@.ObjXML)

END

CREATE PROCEDURE SelectObj

@.ObjID int

AS

BEGIN

SELECT ObjXML

FROM ObjTable

WHERE ObjID = @.ObjID

END

I am also assuming that you have class Ojb with three properties property1, property2 and property3 and a form with 4 textboxes

Here is how you can serialize an object and save it in an XML field. (There might be some better way of doing this but sofar no one made a comment on this)

Code Snippet

Obj c = new Obj();

c.property1 = textBox1.Text;

c.property2 = textBox2.Text;

c.property3 = textBox3.Text;

XmlSerializer s = new XmlSerializer(typeof(Obj));

System.Text.StringBuilder builder = new System.Text.StringBuilder();

s.Serialize(XmlWriter.Create(builder),c);

SqlConnection conn = new SqlConnection();

conn.ConnectionString = @."Data Source=Server;Initial Catalog=database;Integrated Security=SSPI;";

conn.Open();

SqlCommand command = conn.CreateCommand();

command.CommandText = "InsertObj";

command.CommandType = System.Data.CommandType.StoredProcedure;

command.Parameters.Add("@.ObjXML", System.Data.SqlDbType.Xml);

command.Parameters[0].Value = builder.ToString();

command.ExecuteNonQuery();

conn.Close();

And this is how you can deserialize an XML field and get back the saved object.

Code Snippet

XmlReaderSettings set = new XmlReaderSettings();

set.ConformanceLevel = ConformanceLevel.Fragment;

Obj c = new Obj();

SqlConnection conn = new SqlConnection();

conn.ConnectionString = @."Data Source=server;Initial Catalog=database;Integrated Security=SSPI;";

conn.Open();

SqlCommand command = conn.CreateCommand();

command.CommandText = "SelectObj";

command.CommandType = System.Data.CommandType.StoredProcedure;

command.Parameters.Add("@.ObjID", System.Data.SqlDbType.Int);

//taking the input from textBox4.

command.Parameters[0].Value = Convert.ToInt32(textBox4.Text);

SqlDataReader datareader = command.ExecuteReader();

System.Text.StringBuilder builder = new System.Text.StringBuilder();

XmlSerializer s = new XmlSerializer(typeof(Obj));

while(datareader.Read())

{

builder.Append(datareader[0]);

}

TextReader tr = new StringReader(builder.ToString());

c = (CObj)s.Deserialize(tr);

tr.Close();

textBox1.Text = c.property1;

textBox2.Text = c.property2;

textBox3.Text = c.property3;

I hope it helps.

Read, write and update xml data type.

Hi All,

I would like to learn about xml data type of sql server 2005. I am using c# to develop a project that will use sql server express as a database. What I want to accomplish in my project is to serialize an object and save into a field with xml data type. Also I want to have same functionality in other way around. Retrieve this xml representation of the object, Deserialize it so get the saved object back into application.

I would be happy If you can provide me some code which shows how to accomplish this task or some links that directs me to the appropriate docs.

Thanks in advance.

There is lots of material on MSDN, there is a section about the xml data type with subsections about the methods of the xml data type (i.e. query, value, exist, modify, nodes) and the XML DML (XML data modification language).|||

Hi Martin,

Thanks for the reply and links. I haven't gone through the links you sent completly but I think the subject I typed here is misleading so let me explain a bit more, the difficulty I have. . I have no problem with creating a table with an xml type field. I believe by reading the links you have sent I can perform insert, update and delete functions. My difficulty starts just after the seriliazation of an object or just before the deserialization of the xml data I read from xml field. Both serialize and deserialize methods trys to write/read to/from a file or a stream. All I want is to hold this xml in a data structure where I can use it at the time of serialization or deserialization.

The original situaltion:

I have a form to be filled out by the users of my application. Since there are so many fields of data in this form I dont want to create a table with somany fields. So I am planing to hold info entered by user in an xml field. (and ofcourse I should be able to read the data back from this xml field and display in the app)

Thanks.

|||

Got it worked Smile

I used string/TextWriter and string/TextReader combinations and worked fine. Thanks.

FlatWhite

|||

Hi FlatWhite

I would like to do the same thing you are doing. Could you provide some code snippets for me on how to do it?

Thanks

|||

Well I am neither SQL nor C# expert so you can use my code at your own risk J

First of all I am assuming that you have an SQL database table which has ID and XML fields and also you have InsertObj and SelectObj stored procedures.

TABLE : ObjectTable

ObjID-int-identity

ObjXML-XML

SPs : InsertObj

SelectObj

Code Snippet

CREATE PROCEDURE InsertObj

@.ObjXML xml

AS

BEGIN

INSERT INTO ObjectTable (ObjXML)

VALUES (@.ObjXML)

END

CREATE PROCEDURE SelectObj

@.ObjID int

AS

BEGIN

SELECT ObjXML

FROM ObjTable

WHERE ObjID = @.ObjID

END

I am also assuming that you have class Ojb with three properties property1, property2 and property3 and a form with 4 textboxes

Here is how you can serialize an object and save it in an XML field. (There might be some better way of doing this but sofar no one made a comment on this)

Code Snippet

Obj c = new Obj();

c.property1 = textBox1.Text;

c.property2 = textBox2.Text;

c.property3 = textBox3.Text;

XmlSerializer s = new XmlSerializer(typeof(Obj));

System.Text.StringBuilder builder = new System.Text.StringBuilder();

s.Serialize(XmlWriter.Create(builder),c);

SqlConnection conn = new SqlConnection();

conn.ConnectionString = @."Data Source=Server;Initial Catalog=database;Integrated Security=SSPI;";

conn.Open();

SqlCommand command = conn.CreateCommand();

command.CommandText = "InsertObj";

command.CommandType = System.Data.CommandType.StoredProcedure;

command.Parameters.Add("@.ObjXML", System.Data.SqlDbType.Xml);

command.Parameters[0].Value = builder.ToString();

command.ExecuteNonQuery();

conn.Close();

And this is how you can deserialize an XML field and get back the saved object.

Code Snippet

XmlReaderSettings set = new XmlReaderSettings();

set.ConformanceLevel = ConformanceLevel.Fragment;

Obj c = new Obj();

SqlConnection conn = new SqlConnection();

conn.ConnectionString = @."Data Source=server;Initial Catalog=database;Integrated Security=SSPI;";

conn.Open();

SqlCommand command = conn.CreateCommand();

command.CommandText = "SelectObj";

command.CommandType = System.Data.CommandType.StoredProcedure;

command.Parameters.Add("@.ObjID", System.Data.SqlDbType.Int);

//taking the input from textBox4.

command.Parameters[0].Value = Convert.ToInt32(textBox4.Text);

SqlDataReader datareader = command.ExecuteReader();

System.Text.StringBuilder builder = new System.Text.StringBuilder();

XmlSerializer s = new XmlSerializer(typeof(Obj));

while(datareader.Read())

{

builder.Append(datareader[0]);

}

TextReader tr = new StringReader(builder.ToString());

c = (CObj)s.Deserialize(tr);

tr.Close();

textBox1.Text = c.property1;

textBox2.Text = c.property2;

textBox3.Text = c.property3;

I hope it helps.

Monday, March 26, 2012

Read only permissions for report writer

I have an msde database (SQL Server 2000) with an web front end. I would
like to create an MS Access Project to allow certain users to create ad hoc
reports.
I have created a new login named Reporter and connected to the msde database
using this user. This user has dbreadonly permissions.
This works to a certain extent in that new reports can be created based on
existing tables. However, I would like the user to be able to create their
own select queries and cannot find a way to manage this. I recieve a
message saying the user needs 'Create Procedure' rights.
Can anyone tell me how I can let Reporter create their own queries but not
add/edit/delete any existing data?
Many thanks
June
hi June,
June Macleod wrote:
> I have an msde database (SQL Server 2000) with an web front end. I
> would like to create an MS Access Project to allow certain users to
> create ad hoc reports.
> I have created a new login named Reporter and connected to the msde
> database using this user. This user has dbreadonly permissions.
> This works to a certain extent in that new reports can be created
> based on existing tables. However, I would like the user to be able
> to create their own select queries and cannot find a way to manage
> this. I recieve a message saying the user needs 'Create Procedure'
> rights.
> Can anyone tell me how I can let Reporter create their own queries
> but not add/edit/delete any existing data?
> Many thanks
> June
if you are required to allow "CREATE PROC" statement you have to grant
membership to ddladmin database role but, with such a permission, Reporter
can even create new tables and of course access/modify their data..
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.10.0 - DbaMgr ver 0.56.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
|||better,
if you only are required to create procedures, you can grant that specific
permission to Reporte user like
GRANT CREATE PROCEDURE TO [Reporter]
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.10.0 - DbaMgr ver 0.56.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply

Read Only Database

Hi guys,
I'm using SQL Server 2005 Express. When i'm attaching My project database through "SQl Server Management Studio" The database is getting attached as a 'Read only' database. But when i'm attaching the same database from command prompt or using a batch file it is getting attached normally.
The database is from another system. It is behaving the same on the parent system on which it is developed.

Look at the attributes and the permissions:

"A variation of this issue is when the user that opens the user instance connection has read permissions on the database files but does not have write permissions. In this case, SQL Server attaches the database as a READ_ONLY database. If you get a message saying that the database is opened as read only, you need to change the permissions on the database file. "

http://msdn2.microsoft.com/en-us/library/bb264564.aspx

Jens K. Suessmeyer

http://www.sqlserver2005.de

|||Hi Jens
thankQ very much for your reply.
Can you suggest me how can i change the permissions on the database file.
I've given full access permissions for the folder contaning the database files, but still the problem is the same.|||

hi,

you have to grant NTFS permissions to the account running the SQL Server instance..

regards

|||

Make also sure that the appropiate file attributes are not set like readonly / archive. This can also prevent the service from opening the file in a writeable mode.

Jens K. Suessmeyer


http://www.sqlserver2005.de

Friday, March 23, 2012

Read of XML File

Hello,
I do have XML file in c:\project.xml, this file is arround 60 MB file.
Now i want to use
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc and then OPENXML to load xml
into sql server table, so how can i pass that xml file to
EXEC sp_xml_preparedocument
Pls helpTry this:
http://www.sqlxml.org/faqs.aspx?faq=39
--
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"mvp" <mvp@.discussions.microsoft.com> wrote in message
news:B51412BA-DDD2-443C-97B4-4E4E76358A2E@.microsoft.com...
> Hello,
> I do have XML file in c:\project.xml, this file is arround 60 MB file.
> Now i want to use
> EXEC sp_xml_preparedocument @.idoc OUTPUT, @.doc and then OPENXML to load
xml
> into sql server table, so how can i pass that xml file to
> EXEC sp_xml_preparedocument
> Pls help|||Is there anyway so that i c an do bulk load..because my .xml file is very
big, arround 60MB. Pls let me know
"Narayana Vyas Kondreddi" wrote:

> Try this:
> http://www.sqlxml.org/faqs.aspx?faq=39
> --
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
>
> "mvp" <mvp@.discussions.microsoft.com> wrote in message
> news:B51412BA-DDD2-443C-97B4-4E4E76358A2E@.microsoft.com...
> xml
>
>

Wednesday, March 21, 2012

read data from a csv file and insert it in a sql server databse table

Hai Everbody,

for me in my project i want to read data from a csv file and insert it in a sql server databse table.The csv file may contain n number of columns,but i want only certain columns from that, and insert it in the database table.How to achieve this. Plz help me it is urgent. Thanks in advance.

Thanks and regards

Biju.S.G

http://www.dotnetspider.com/kb/Article1082.aspx

http://www.devarticles.com/c/a/ASP.NET/Reading-a-Delimited-File-Using-ASP.Net-and-VB.Net/

Monday, March 12, 2012

RDLC not recognizing DataSet

ASP.NET 2.0 Project
Added
rdlc file
DataSet with DataTable to be populated dynamically at runtime
I cannot set DataSetName in the dropdown -- it does not recognize my
DataSet and I cannot type into it.
If I compile I receive this error for my RDLC
"Error 1 The table 'table1' is in the report body but the report has
no data set. Data regions are not allowed in reports without
datasets."Are you saying that in the "Report Data Sources" window you do not see any
datasets (it actually shows the datatables) in the "Project Data Sources"
dropdown?
Where exactly are you trying to enter this dataset
Do you have an xsd created?
In the datasources window (Which shows when you are looking at a report),
what do you see? And can you create a new datasource from there?
// Andrew
> ASP.NET 2.0 Project
> Added
> rdlc file
> DataSet with DataTable to be populated dynamically at runtime
> I cannot set DataSetName in the dropdown -- it does not recognize my
> DataSet and I cannot type into it.
> If I compile I receive this error for my RDLC
> "Error 1 The table 'table1' is in the report body but the report has
> no data set. Data regions are not allowed in reports without
> datasets."
>

Friday, March 9, 2012

rdl or rdlc for custom reports

Are custom reports going to carry on using the rdlc extension. If so is the rdlc extension going to be associated with the reporting project designer. Currently rdlc files only show up the designer and not the data or preview tabs in BIDS.

Paul's documentation blog post refers to rdl rather than rdlc files.

Simon, the final release of SP2 will default to RDL files rather than RDLC files.

Cheers,
Dan

|||

If you don't want to rename your report files to .RDLC for the November CTP, you can type "*.RDL" into the custom reports dialog and hit enter. The report will load just fine... however, any subsequent drilldown actions to other reports will probably default to a .RDLC extension instead of .RDL.

Paul A. Mestemaker II
Program Manager
Microsoft SQL Server Manageability
http://blogs.msdn.com/sqlrem/

|||Exactly, thats what I found :)

Wednesday, March 7, 2012

RDA with Identity column.

Hi Everyone:

I am new to Mobile programming. I am now working on a mobile project. I encounter an issue when I sync the data:

cause I can't modify the schema, so I have to use RDA instead of Merge replication on sql server 2005.

However, There is an identiy column on each table I will pull them down to local mobile database. And I will use those identity columns to connect tables. Even worse, the photo's new name will combine the photoID which is an identity column. There would an issue, if i sync data, the photoID would be same on different local mobile databases. And there would be generate same identity value when users sync data.

How can I avoid those issues? If you have any good ideas, please help me out so that I can meet the project deadline.

Thanks

James

Anyone knows how to manually handle identity management.

Cause my identity column will clash when Sync data.

James

|||

You need to call

ALTER TABLE <TableName> ALTER COLUMN <ColumnName> <ColumnDataType> IDENTITY(<Seed>,<Step>)

to set the different identity on the pulled table.

Note, only Seed and Step can be changed in the above table.

Thanks,

Laxmi Narsimha Rao ORUGANTI

|||

Hi Laxmi,

Thank you for your reply. I realize that I can use the command you gave to change the SEED range to avoid the clash. But if I change seed, when I push the data back to Remote SQL server 2005 database, should I disable the identity column on remote database, then push mobile client table data, then set identity column back on remote DB. It seems lots of work to manually handle identity column clash. Do we have any alternative way to do it, since I can't use merge replication to change the database schema, what about XML web service? I think should be same, but if we use Web Service, the performance should be down 10-15%, that's why i don't wanna use it since we choose SQL server 2005 as our database.

Your reply is really appreciated. Thanks!

James

|||

I need to point is that someone will work on remote db through classical ASP. If I change the identity Seed. It will effect mobile client?

If anybody has the same issues?

Thanks

James

|||

No need to worry about disabling the IDENTITY on server. RDA while pushing automatically does "SET IDENTITY_INSERT <TableName> ON/OFF" on SQL Server to get the same IDENTITY column values onto the server table.

Thanks,

Laxmi

|||

Thank Laxmi,

your reply does help me. I will try it out. But we have 200 hundred of Mobile clients. We have to set the identity range for each one.

Any other good ideas for solving the identity clash.

Thanks.

James

|||That is why there is Merge Replication! Why not go for that?|||

Because I can't modify the Sql server 2005 DB schema. They are using identity ID. I wish I could use Merge replication. I can save my code lines as well.

Thank you . Laxmi. You are the rock!

James

|||Same here, merge replication is not a option.

Anyone found a suitable solution for this challenge?

Thanx
|||What I have done is to set the ID range for each person. So that they won't clash.

RDA with Identity column.

Hi Everyone:

I am new to Mobile programming. I am now working on a mobile project. I encounter an issue when I sync the data:

cause I can't modify the schema, so I have to use RDA instead of Merge replication on sql server 2005.

However, There is an identiy column on each table I will pull them down to local mobile database. And I will use those identity columns to connect tables. Even worse, the photo's new name will combine the photoID which is an identity column. There would an issue, if i sync data, the photoID would be same on different local mobile databases. And there would be generate same identity value when users sync data.

How can I avoid those issues? If you have any good ideas, please help me out so that I can meet the project deadline.

Thanks

James

Anyone knows how to manually handle identity management.

Cause my identity column will clash when Sync data.

James

|||

You need to call

ALTER TABLE <TableName> ALTER COLUMN <ColumnName> <ColumnDataType> IDENTITY(<Seed>,<Step>)

to set the different identity on the pulled table.

Note, only Seed and Step can be changed in the above table.

Thanks,

Laxmi Narsimha Rao ORUGANTI

|||

Hi Laxmi,

Thank you for your reply. I realize that I can use the command you gave to change the SEED range to avoid the clash. But if I change seed, when I push the data back to Remote SQL server 2005 database, should I disable the identity column on remote database, then push mobile client table data, then set identity column back on remote DB. It seems lots of work to manually handle identity column clash. Do we have any alternative way to do it, since I can't use merge replication to change the database schema, what about XML web service? I think should be same, but if we use Web Service, the performance should be down 10-15%, that's why i don't wanna use it since we choose SQL server 2005 as our database.

Your reply is really appreciated. Thanks!

James

|||

I need to point is that someone will work on remote db through classical ASP. If I change the identity Seed. It will effect mobile client?

If anybody has the same issues?

Thanks

James

|||

No need to worry about disabling the IDENTITY on server. RDA while pushing automatically does "SET IDENTITY_INSERT <TableName> ON/OFF" on SQL Server to get the same IDENTITY column values onto the server table.

Thanks,

Laxmi

|||

Thank Laxmi,

your reply does help me. I will try it out. But we have 200 hundred of Mobile clients. We have to set the identity range for each one.

Any other good ideas for solving the identity clash.

Thanks.

James

|||That is why there is Merge Replication! Why not go for that?|||

Because I can't modify the Sql server 2005 DB schema. They are using identity ID. I wish I could use Merge replication. I can save my code lines as well.

Thank you . Laxmi. You are the rock!

James

|||Same here, merge replication is not a option.

Anyone found a suitable solution for this challenge?

Thanx|||What I have done is to set the ID range for each person. So that they won't clash.

RDA with Identity column.

Hi Everyone:

I am new to Mobile programming. I am now working on a mobile project. I encounter an issue when I sync the data:

cause I can't modify the schema, so I have to use RDA instead of Merge replication on sql server 2005.

However, There is an identiy column on each table I will pull them down to local mobile database. And I will use those identity columns to connect tables. Even worse, the photo's new name will combine the photoID which is an identity column. There would an issue, if i sync data, the photoID would be same on different local mobile databases. And there would be generate same identity value when users sync data.

How can I avoid those issues? If you have any good ideas, please help me out so that I can meet the project deadline.

Thanks

James

Anyone knows how to manually handle identity management.

Cause my identity column will clash when Sync data.

James

|||

You need to call

ALTER TABLE <TableName> ALTER COLUMN <ColumnName> <ColumnDataType> IDENTITY(<Seed>,<Step>)

to set the different identity on the pulled table.

Note, only Seed and Step can be changed in the above table.

Thanks,

Laxmi Narsimha Rao ORUGANTI

|||

Hi Laxmi,

Thank you for your reply. I realize that I can use the command you gave to change the SEED range to avoid the clash. But if I change seed, when I push the data back to Remote SQL server 2005 database, should I disable the identity column on remote database, then push mobile client table data, then set identity column back on remote DB. It seems lots of work to manually handle identity column clash. Do we have any alternative way to do it, since I can't use merge replication to change the database schema, what about XML web service? I think should be same, but if we use Web Service, the performance should be down 10-15%, that's why i don't wanna use it since we choose SQL server 2005 as our database.

Your reply is really appreciated. Thanks!

James

|||

I need to point is that someone will work on remote db through classical ASP. If I change the identity Seed. It will effect mobile client?

If anybody has the same issues?

Thanks

James

|||

No need to worry about disabling the IDENTITY on server. RDA while pushing automatically does "SET IDENTITY_INSERT <TableName> ON/OFF" on SQL Server to get the same IDENTITY column values onto the server table.

Thanks,

Laxmi

|||

Thank Laxmi,

your reply does help me. I will try it out. But we have 200 hundred of Mobile clients. We have to set the identity range for each one.

Any other good ideas for solving the identity clash.

Thanks.

James

|||That is why there is Merge Replication! Why not go for that?|||

Because I can't modify the Sql server 2005 DB schema. They are using identity ID. I wish I could use Merge replication. I can save my code lines as well.

Thank you . Laxmi. You are the rock!

James

|||Same here, merge replication is not a option.

Anyone found a suitable solution for this challenge?

Thanx|||What I have done is to set the ID range for each person. So that they won't clash.