Showing posts with label application. Show all posts
Showing posts with label application. Show all posts

Friday, March 30, 2012

How to Insert Multiple Records into sql 2000 table at once ?

hello,
I am new to Slq 2000 Database,Now I create an asp.net application with sql 2000,
in my database I have two 2 table lets' say "OrderHead" and "OrderDetail",they look like this:
OrderHead orderdetail
--order no --orderno
--issuedate --itemname
--supplier --desccription
--amount --price
--Qty
Now I created a user-defined Collection class to storage order detail data in memory
and bind to a datagrid control.
I can transfer Collection data to xml file ,my problem as below :
There have multiple records data in my xml file,and I want to send the xml file as argument to a store procedure in sql 2000

anyone can give me some advise or some sample code ?

thanks in advanced!See links below:

1. http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
2. http://www.eggheadcafe.com/articles/20030627c.asp|||hi, thanks a lot,I will browse the web page you give me .

Wednesday, March 28, 2012

how to insert data in to two tables?

hi,

i have got a problem, iam creating an asp.net application, but i pretend to insert data in two different tables, but i have no ideia how to do this.Can you help to solve this problem? please........

So, you need to insert data into two different tables? What database are you using? If you are using SQL or MSDE, you would use 2 insert statements or a stored procedure.|||

scosta wrote:

hi,

i have got a problem, iam creating an asp.net application, but ipretend to insert data in two different tables, but i have no ideia howto do this.Can you help to solve this problem? please........


This is as simple as executing two SQL INSERTS in sequence or as complicated as writing a stored proc that does the same thing.
Time to pick up an introductory book on SQL Server and ADO.NET my friend.
|||

iam using Sql, and i want to use the way to solve the problem, or 2 insert statements or a stored procedure.

how to insert data in to two tables?

hi,

iam creating an asp.net application the database is created on the SQLSERVER, but i have a problem, i pretend to insert data in to 2 tables and i have no ideia how to do this. Can you help me to solve this problem? Please....

you would need 2 insert statements. check out books online for syntax on INSERT. You could also use stored procedures to have all the inserts in it so you can get your job done in one trip to the server.sql

Friday, March 23, 2012

How to increase the SQL Server memory

We are using SQL server 7.0, our users use to connect to SQL server remotely using Visual Basic Application. When all the users are connected it keeps on increasing the memory utilization and at 1,836,848 KB memory utilization it stops increasing the memory i.e memory utilization become stangnet. The actual amount of physical Memory is around 5GB but SQL server dont increase it after the treshhold level and the performance of the server get affected badly. Any one please suggest me the possible solution.In Enterprise Manager,
- right click on the server name and choose properties.
- choose memory tab

You should be able to set your min/max memory settings there. Also look into worker threads (on the processor tab).

Something else to think about,
How big is the DB (Gigs) ? How big are the tables being referenced? Perhaps something could be re-designed to make things more efficient. Are there a lot of table scans where you could have indexes, etc..?

Also,
Open the performance moniter and check the sql counters..

More info at -> http://www.sql-server-performance.com/performance_monitor_tips.asp|||It looks like you're running Standard Edition of SQL2K, which will not recognize any more memory, period! You need to upgrade to Enterprise and then you'll have more options:

1. /3GB in boot.ini will allow SQL Server to use more than the default 2GB
2. /PAE in boot.ini and enabling AWE on SQL Server will give SQL service whatever amount you specify.

Wednesday, March 21, 2012

How to include SQL Express in Installation Package and change some option?

Hi, there,
I'm working on a windows application project which uses SQL Express as
database.
I found I can include SQL Server 2005 Express Edition in the installation
project as Prerequests,
that's cool.
But I need do more things, I want to change the "Authentication Mode" from
"Windows Authentication mode"
(which is default) to "SQL Server Authentication mode" and assign a "default
password" to user "sa", and
I want to attach a database file which will be include on the installation
disc.
So what shall I do? Write some script in the installation project?
Does SQL Express provide any program interface to do that?
It seems there is no help content for this in the MSDN and I did some search
job and got nothing.
Help needed. Thank you.
Best wishes!
I could write a chapter on this but here it is in a nutshell.
You need to use the Unattended Install tenplate.ini file along with the
LOGName and Datasource.xml.
Here is a fantastic article.
http://www.devx.com/dbzone/Article/31648
thanks,
/*
Warren Brunk - MCITP - SQL 2005, MCDBA
www.techintsolutions.com
*/
"Philip.Arbin" <philip@.newsgroups.nospam> wrote in message
news:OvWXUO85GHA.508@.TK2MSFTNGP06.phx.gbl...
> Hi, there,
> I'm working on a windows application project which uses SQL Express as
> database.
> I found I can include SQL Server 2005 Express Edition in the installation
> project as Prerequests,
> that's cool.
> But I need do more things, I want to change the "Authentication Mode" from
> "Windows Authentication mode"
> (which is default) to "SQL Server Authentication mode" and assign a
> "default password" to user "sa", and
> I want to attach a database file which will be include on the installation
> disc.
> So what shall I do? Write some script in the installation project?
> Does SQL Express provide any program interface to do that?
> It seems there is no help content for this in the MSDN and I did some
> search job and got nothing.
> Help needed. Thank you.
> Best wishes!
>
|||Hmm.....
Thank you.
I have read it, and there is really something interesting.
But there is another thing I can not do with this article.
I want to open Name Pipe and TCP connection of the SQL EXPRESS during the
setup,
but there is no such setting in the template.ini file.
Any other help?
"Warren Brunk" <wbrunk@.techintsolutions.com> wrote in message
news:uFytSE%235GHA.3592@.TK2MSFTNGP05.phx.gbl...
>I could write a chapter on this but here it is in a nutshell.
> You need to use the Unattended Install tenplate.ini file along with the
> LOGName and Datasource.xml.
> Here is a fantastic article.
> http://www.devx.com/dbzone/Article/31648
>
> thanks,
> --
> /*
> Warren Brunk - MCITP - SQL 2005, MCDBA
> www.techintsolutions.com
> */
>
> "Philip.Arbin" <philip@.newsgroups.nospam> wrote in message
> news:OvWXUO85GHA.508@.TK2MSFTNGP06.phx.gbl...
>
|||Philip,
All you need to do is edit the package.xml file - you can specify the
command line parameters you want to use for installing SQLExpress. The file
is located in
C:\Program Files\Microsoft Visual Studio
8\SDK\v2.0\BootStrapper\Packages\SqlExpress\en
The default setup is
Arguments='-q /norebootchk /qn reboot=ReallySuppress addlocal=all
instancename=SQLEXPRESS SQLAUTOSTART=1'
You might want to change it to something like
Arguments='-q /norebootchk /qn reboot=ReallySuppress addlocal=all
instancename=SQLEXPRESS SQLAUTOSTART=1 SECURITYMODE=SQL SAPWD=yoursapw
DISABLENETWORKPROTOCOLS=0'
See the readme file for SQLExpress for the command line options. That will
get SQLExpress installed the way you want it. Use a custom action dll to
install your db, attach it, set up the user accounts you want, etc.
Russ Stevens
|||Ah haaaaaa!
This is right the solution I am looking for!
Powerful!
Thank you very much!
"Russell Stevens" <rustyprogrammer@.online.nospam> wrote in message
news:OkMqQxy8GHA.5092@.TK2MSFTNGP04.phx.gbl...
> Philip,
> All you need to do is edit the package.xml file - you can specify the
> command line parameters you want to use for installing SQLExpress. The
> file is located in
> C:\Program Files\Microsoft Visual Studio
> 8\SDK\v2.0\BootStrapper\Packages\SqlExpress\en
> The default setup is
> Arguments='-q /norebootchk /qn reboot=ReallySuppress addlocal=all
> instancename=SQLEXPRESS SQLAUTOSTART=1'
> You might want to change it to something like
> Arguments='-q /norebootchk /qn reboot=ReallySuppress addlocal=all
> instancename=SQLEXPRESS SQLAUTOSTART=1 SECURITYMODE=SQL SAPWD=yoursapw
> DISABLENETWORKPROTOCOLS=0'
> See the readme file for SQLExpress for the command line options. That will
> get SQLExpress installed the way you want it. Use a custom action dll to
> install your db, attach it, set up the user accounts you want, etc.
> Russ Stevens
>

How to include MSDE with Setup of custom applications

I am using VS .NET 2003 Bootstrapper Plug-In to create an
installer that redistribute the .NET Framework 1.1 and
MDAC 2.8 with my application.
How can I include MSDE and provide the switches in order
to install MSDE on clients machine as well?
Thanks
Hi,
Unfortunately, all the auto-install options currently have "issues". I'd
strongly suggest you:
1. Configure the setup.ini file to have your default settings.
2. Get the client to run the setup.exe program to install the MSDE.
HTH,
Greg Low [MVP]
MSDE Manager SQL Tools
www.whitebearconsulting.com
"pankaj banga" <pankaj@.discussions.microsoft.com> wrote in message
news:12f201c4a8db$5d598ab0$a501280a@.phx.gbl...
>I am using VS .NET 2003 Bootstrapper Plug-In to create an
> installer that redistribute the .NET Framework 1.1 and
> MDAC 2.8 with my application.
> How can I include MSDE and provide the switches in order
> to install MSDE on clients machine as well?
> Thanks
|||Thanks HTH,
Then how would I create my tables, stored procs and load
client specific data into tables. Actually I am new to
all this. I read about msde bootstrap installer, are
there issues with it as well?

>--Original Message--
>Hi,
>Unfortunately, all the auto-install options currently
have "issues". I'd
>strongly suggest you:
>1. Configure the setup.ini file to have your default
settings.
>2. Get the client to run the setup.exe program to
install the MSDE.
>HTH,
>--
>Greg Low [MVP]
>MSDE Manager SQL Tools
>www.whitebearconsulting.com
>"pankaj banga" <pankaj@.discussions.microsoft.com> wrote
in message[vbcol=seagreen]
>news:12f201c4a8db$5d598ab0$a501280a@.phx.gbl...
an[vbcol=seagreen]
order
>
>.
>
|||hi,
"pankaj banga" <pankaj@.discussions.microsoft.com> ha scritto nel
messaggio news:230901c4a950$1bb0dcb0$a301280a@.phx.gbl
> Thanks HTH,
> Then how would I create my tables, stored procs and load
> client specific data into tables. Actually I am new to
> all this. I read about msde bootstrap installer, are
> there issues with it as well?
>
Microsoft provides a deployment toolkit, in release candidate at the current
time, you can dowload from
http://www.microsoft.com/downloads/d...displaylang=en
I did not installed it, but I think some database deployment feature are
present... and some drawbacks of this toolkit have been posted here... don't
know the current state and/or the final release...
personally I do deploy apps with a companion tool which will read and
execute DDL scripts as long as INSERT INTO scipts, BCP and so on.. other
ways are backup/restore and sp_attach_db
I already discused these 3 methods of mine in http://tinyurl.com/6ux7p and
http://tinyurl.com/4x8pv ...
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.9.1 - DbaMgr ver 0.55.1
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
sql

how to include database with installation files of msde

I have created an application using VB6. The application uses MSDE to
access data. How do I include the required database with the installation
package.
Daniel
In the package & deployment wizard, include it in the "other files" listing
you get to complete as part of creating the setup package.
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Daniel" <dwbnews@.hotmail.com> wrote in message
news:#WXyl04REHA.3124@.TK2MSFTNGP12.phx.gbl...
: I have created an application using VB6. The application uses MSDE to
: access data. How do I include the required database with the installation
: package.
:
: Daniel
:
:
|||Are you saying that a database in MSDE is saved on the drive as an actual
file?
Daniel
"Randy Birch" <rgb_removethis@.mvps.org> wrote in message
news:uxkYY84REHA.3016@.tk2msftngp13.phx.gbl...
> In the package & deployment wizard, include it in the "other files"
listing
> you get to complete as part of creating the setup package.
> --
> Randy Birch
> MVP Visual Basic
> http://vbnet.mvps.org/
> Please respond only to the newsgroups so all can benefit.
>
> "Daniel" <dwbnews@.hotmail.com> wrote in message
> news:#WXyl04REHA.3124@.TK2MSFTNGP12.phx.gbl...
> : I have created an application using VB6. The application uses MSDE to
> : access data. How do I include the required database with the
installation
> : package.
> :
> : Daniel
> :
> :
>
|||MSDE is SQL Server, and for each database in SQL Server, you have at least two files, a primary database file
(typically .mdf) and at least one transaction log file (typically .ldf). You can detach the files, ship them
with your app and after msde is installed attach them again. Read about sp_detach_db and sp_attach_db i Books
Online.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Daniel" <dwbnews@.hotmail.com> wrote in message news:%23aKOEJ5REHA.3628@.TK2MSFTNGP12.phx.gbl...
> Are you saying that a database in MSDE is saved on the drive as an actual
> file?
> Daniel
> "Randy Birch" <rgb_removethis@.mvps.org> wrote in message
> news:uxkYY84REHA.3016@.tk2msftngp13.phx.gbl...
> listing
> installation
>
|||Hi Daniel
Also check out:
http://support.microsoft.com/default...-us;Q314546#10
John
"Daniel" <dwbnews@.hotmail.com> wrote in message
news:%23aKOEJ5REHA.3628@.TK2MSFTNGP12.phx.gbl...
> Are you saying that a database in MSDE is saved on the drive as an actual
> file?
> Daniel
> "Randy Birch" <rgb_removethis@.mvps.org> wrote in message
> news:uxkYY84REHA.3016@.tk2msftngp13.phx.gbl...
> listing
> installation
>
|||Sorry ... my error ... I read MSDE and thought Access MDB. I didn't see the
cross-post to the sqlserver groups.
Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Daniel" <dwbnews@.hotmail.com> wrote in message
news:#aKOEJ5REHA.3628@.TK2MSFTNGP12.phx.gbl...
: Are you saying that a database in MSDE is saved on the drive as an actual
: file?
:
: Daniel
:
: "Randy Birch" <rgb_removethis@.mvps.org> wrote in message
: news:uxkYY84REHA.3016@.tk2msftngp13.phx.gbl...
: > In the package & deployment wizard, include it in the "other files"
: listing
: > you get to complete as part of creating the setup package.
: >
: > --
: >
: > Randy Birch
: > MVP Visual Basic
: > http://vbnet.mvps.org/
: > Please respond only to the newsgroups so all can benefit.
: >
: >
: > "Daniel" <dwbnews@.hotmail.com> wrote in message
: > news:#WXyl04REHA.3124@.TK2MSFTNGP12.phx.gbl...
: > : I have created an application using VB6. The application uses MSDE to
: > : access data. How do I include the required database with the
: installation
: > : package.
: > :
: > : Daniel
: > :
: > :
: >
:
:

How to Improve SQL Server performance with web application

Hi all,
I am facing some difficulties with web application performance. I have
web application in front end and SQL server 2000 Enterprise Edition in
Backend. Now , some web pages in application takes very long time
while getting data from SQL server. I want to improve the speed with
which the some web pages load.
Do anyone has idea of any third-party tools that can help me with
this situation. So, that I can constantly monitor performance of
Database with Web application.
Any help will be appriated.
Thanks in Advance.
alps
Hi
"alps" wrote:

> Hi all,
> I am facing some difficulties with web application performance. I have
> web application in front end and SQL server 2000 Enterprise Edition in
> Backend. Now , some web pages in application takes very long time
> while getting data from SQL server. I want to improve the speed with
> which the some web pages load.
> Do anyone has idea of any third-party tools that can help me with
> this situation. So, that I can constantly monitor performance of
> Database with Web application.
>
> Any help will be appriated.
> Thanks in Advance.
> alps
>
SQL Server profile will be able to monitor your database, but you may want
to control when it is running. From the profile you can analyse what queries
are running slowly. This analysis can be done by hand or using a tool such as
cleartrace http://www.cleardata.biz/cleartrace/default.aspx You should also
check for queries that return large amounts of data as this can take time to
render. Techniques such as paging may help to improve performance and only
return a manageable amount of data. You can analyses your web logs to find
pages that take a long time to load, you should be able to find free tools on
the internet that help you to do this.
Perfmon will also help you monitor system resources.
John

How to Improve SQL Server performance with web application

Hi all,
I am facing some difficulties with web application performance. I have
web application in front end and SQL server 2000 Enterprise Edition in
Backend. Now , some web pages in application takes very long time
while getting data from SQL server. I want to improve the speed with
which the some web pages load.
Do anyone has idea of any third-party tools that can help me with
this situation. So, that I can constantly monitor performance of
Database with Web application.
Any help will be appriated.
Thanks in Advance.
alpsHi
"alps" wrote:
> Hi all,
> I am facing some difficulties with web application performance. I have
> web application in front end and SQL server 2000 Enterprise Edition in
> Backend. Now , some web pages in application takes very long time
> while getting data from SQL server. I want to improve the speed with
> which the some web pages load.
> Do anyone has idea of any third-party tools that can help me with
> this situation. So, that I can constantly monitor performance of
> Database with Web application.
>
> Any help will be appriated.
> Thanks in Advance.
> alps
>
SQL Server profile will be able to monitor your database, but you may want
to control when it is running. From the profile you can analyse what queries
are running slowly. This analysis can be done by hand or using a tool such as
cleartrace http://www.cleardata.biz/cleartrace/default.aspx You should also
check for queries that return large amounts of data as this can take time to
render. Techniques such as paging may help to improve performance and only
return a manageable amount of data. You can analyses your web logs to find
pages that take a long time to load, you should be able to find free tools on
the internet that help you to do this.
Perfmon will also help you monitor system resources.
John

Monday, March 19, 2012

How to Improve SQL Server performance with web application

Hi all,
I am facing some difficulties with web application performance. I have
web application in front end and SQL server 2000 Enterprise Edition in
Backend. Now , some web pages in application takes very long time
while getting data from SQL server. I want to improve the speed with
which the some web pages load.
Do anyone has idea of any third-party tools that can help me with
this situation. So, that I can constantly monitor performance of
Database with Web application.
Any help will be appriated.
Thanks in Advance.
alpsHi
"alps" wrote:

> Hi all,
> I am facing some difficulties with web application performance. I have
> web application in front end and SQL server 2000 Enterprise Edition in
> Backend. Now , some web pages in application takes very long time
> while getting data from SQL server. I want to improve the speed with
> which the some web pages load.
> Do anyone has idea of any third-party tools that can help me with
> this situation. So, that I can constantly monitor performance of
> Database with Web application.
>
> Any help will be appriated.
> Thanks in Advance.
> alps
>
SQL Server profile will be able to monitor your database, but you may want
to control when it is running. From the profile you can analyse what queries
are running slowly. This analysis can be done by hand or using a tool such a
s
cleartrace http://www.cleardata.biz/cleartrace/default.aspx You should also
check for queries that return large amounts of data as this can take time to
render. Techniques such as paging may help to improve performance and only
return a manageable amount of data. You can analyses your web logs to find
pages that take a long time to load, you should be able to find free tools o
n
the internet that help you to do this.
Perfmon will also help you monitor system resources.
John

How to improve performance with a join between 2 table from 2 SQL Servers

I am making a ASP.NET web application that involves 2 SQL Server(A & B).

I created a view in SQL server A pointing to the table in SQL Server B. I found out my application will run REALLY slow when accessing such a view. so I try to avoid using them. But in the case of 2 table joining from 2 different SQL Servers, I have no choice.

Can anyone help me with this?

Thanks!

No you don't need a View which is a query rewrite but you need the OpenRowset function. Try the link below for more.

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

|||that is exactly how I create my view(I used openrowset to create it). So what you suggest is just same thing as what I am doing. It is so slow, I don't know how to improve it.|||

Can anybody have any suggestion except using "OpenRowset" function? Because it is slow and it is what I am using.

I found out that the Collate Character set of the 2 SQL Server is different, will this affect the performance? If so, how could I change it?

Thanks!

|||

When you join between 2 seperate servers, it is possible that all of the data from one servers table is moving to the other server. Possibly even data that is not ultimately required by your join. This is what i would suspect as the cause of the performance issue.

Ive seen similar issue with Access applications ive supported when the Access db was joining a local Access table to a linked sql table. It usually worked ok if one of the tables was very small, but if both tables were large, the application would virtually grind to a halt.

My solution to speed it up was to prefetch exactly the data i needed from the remote server into a temp table in my local server. Then i would join to the temp table.

If i couldnt construct a query to get exactly what i needed, i would added as many constraints as possible to try to eliminate as much unnecessary data as possible from being pulled from the remote server.

How to improve database searhing performance?

Hi, I am using compact framework 1.1 and SQL CE database for my mobile application. My database has a total of 160000 rows of records and whenever i do a query searching, it will take about 20 seconds to look through the whole database if the record does not exist. Is there any method to improve the searching performance? i am using data reader for the query.

Thanks.

If you are using SQL statements now, consider using Seek/SetRange using an index. More information at http://msdn2.microsoft.com/en-us/library/system.data.sqlserverce.sqlcedatareader.seek.aspx

Monday, March 12, 2012

How to Import data from Excel into MS SQL in .Net?

Hi, I'm building a web application in VB.NET 1.1 where users will upload Excel files at this webpage and the web application will transfer the data from the uploaded Excel file into MS SQL 2000. There are around 600-700 records and about 56 columns in the Excel file which is to be uploaded daily. There will be a few different files which I need to implement for as well.

I've sourced for and tried alot of methods. But either they can't satisfy my requirements or they just can't simply work.

- Most simple and direct way I've tried is creating a oledb connection to the Excel file in the following codes...

Function TestUploadData1(ByVal vFile As String) As String
Dim Oleda As System.Data.OleDb.OleDbDataAdapter
Dim Olecn As System.Data.OleDb.OleDbConnection
Dim dt1 As DataTable

Olecn = New System.Data.OleDb.OleDbConnection( _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & vFile & ";" & _ "Extended Properties=Excel 8.0;HDR=Yes")
Olecn.Open()

Dim ExcelCommand As New System.Data.OleDb.OleDbCommand("SELECT INTO [ODBC;Driver={SQL Server};Server=(local);Database=dbSSC;Trusted_Conn ection=yes].[tblOutstanding] FROM [Report$];", Olecn)
ExcelCommand.ExecuteNonQuery()

Olecn.Close()
End Function

But from the above codes I kept getting the error "Could not find installable ISAM." at the line Olecn.Open(). I've tried to set the registry to C:\Windows\System32\msexcl40.dll but to no avail...

- I've tried another method using the OpenRowSet in the following codes
Function TestUploadData2(ByVal vFile As String) As String
Dim cn As SqlConnection
Dim cm As SqlCommand
Dim strSQL As String cn = New SqlConnection("server=localhost; user ID=accessSSC; password=accessSSC541; database=dbSSC")

cn.Open()

strSQL = "INSERT INTO tblOutstanding SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=" & vFile & ";HDR=Yes','SELECT * FROM [Report$]')"
cm = New SqlCommand(strSQL, cn)
cm.ExecuteNonQuery()

cn.Close()
End Function

For the above codes, I kept getting the error "Ad hoc access to OLE DB provider 'Microsoft.Jet.OLEDB.4.0' has been denied. You must access this provider through a linked server." at the line cm.ExecuteNonQuery() and I've tried to disable the Ad Hoc settings in the registry and tried to create a link server but to no avail as well...

- I've tried DTS but I'd need to DTS package to run whenever the users upload a file. Is there an easy way that I can run the designated DTS package to run through my .Net web application?

Any help would be deeply appreciated.
Thanks & Regards,
Keith Chang

Here is a very simple article which you can extend to your needs.

http://davidhayden.com/blog/dave/archive/2006/05/31/2976.aspx

There are some solutions available for this problem. You already tried one. Have a look at this post also.

http://www.dotnetspider.com/qa/Question32454.aspx

Sometimes, even the connections string can be a problem (yours looks fine though)

|||

Here is a small exerpt from one of my projects:

If FileUpload1.HasFileThen

Dim filenameAsString

Dim cmdAs OleDbCommandDim daAsNew OleDbDataAdapter

filename = System.IO.Path.GetTempFileName

FileUpload1.SaveAs(filename)

Dim connAsNew OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filename &";Extended Properties=""Excel 8.0;HDR=No;IMEX=1""")

' Find Sheet Names

Dim SheetsAs Generic.List(OfString)

Sheets = GetSheets(conn)

' Find Header Row

cmd =New OleDbCommand("SELECT * FROM [" & Sheets(0).ToString &"$A:A]", conn)

Dim dshAsNew DataSet

da =New OleDbDataAdapter(cmd)

da.Fill(dsh)

And the GetSheets function:

Function GetSheets(ByVal connAs OleDbConnection)As Generic.List(OfString)

Dim SheetsAsNew Generic.List(OfString)

Dim dtAs DataTable

If conn.State = ConnectionState.ClosedThen

conn.Open()

EndIf

dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,NewObject() {Nothing,Nothing,Nothing,"TABLE"})

' Sheets end in $, but may have quotes around the name, this gets rid of named ranges from the list

Dim dvAsNew DataView(dt,"TABLE_NAME LIKE '%$' OR TABLE_NAME LIKE '%$'''","TABLE_NAME", DataViewRowState.Unchanged)

ForEach drAs DataRowIn dv.ToTable.Rows

If dr("TABLE_NAME").ToString.StartsWith("'")AndAlso dr("TABLE_NAME").ToString.EndsWith("'")Then

'Remove beginning quote, and ending dollar sign quote

Sheets.Add(dr("TABLE_NAME").ToString.Substring(1, Len(dr("TABLE_NAME").ToString) - 3))

Else

'Remove ending dollar sign

Sheets.Add(dr("TABLE_NAME").ToString.Substring(0, Len(dr("TABLE_NAME").ToString) - 1))

EndIf

Next

Return Sheets

EndFunction

|||

Thanks for replying Motley... But I believe your scripts were to extract the data from excel into a datatable. Well I can do that, no problem... Problem is how do I put this data into my MS SQL server?! Is there any way that I can just upload this dataset or datatable straight into the designated table in the MS SQL server?

I'm using .Net 1.1 so I can't use the SQLBulkCopy which is for 2.0 only... but still thanks bullpit.

|||

Once the data is in a dataset, you can then use a sqldataadapter or just iterate through the rows and issue the insert commands.

|||I have thought of that... but problem is that I've around 56 columns and around 600-700 records which will take quite some time to import. And I have around 15 files that need to go through this process... It'd take half a day just to import all these files...|||

Using sqldataadapter in batch mode will be the fastest way to import the data.

|||

Thanks for all help. But I've finally found my own solution to it. I used the DTS and the following code to execute the DTS package prepared to do the transfer in asp.net which did not take more than 2 seconds. Just that I need to open the excel file and adjust the formatting to assure correct importing which takes much longer time around 30 seconds.

'Update respective table (add reference to Microsoft DTSPackage Object Library)
vDTS.LoadFromSQLServer("localhost","dbid","dbpassword", DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default,"pkgpassword", , ,pkgDaysin", )
vDTS.Execute()
vDTS.UnInitialize()
vDTS =Nothing

Hope this is useful to whoever facing the same problem as me.Smile

|||

Hi KeithChang,

I am getting same problem as you mentioned on the first post message. I tried the OPENROWSET AND OPENDATASORUCE Command in .Net 1.1. But its not working.

Please tell me, how to implement this above code .

vDTS.LoadFromSQLServer("localhost","dbid","dbpassword", DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_Default,"pkgpassword", , ,pkgDaysin", )
vDTS.Execute()
vDTS.UnInitialize()
vDTS =Nothing

This is helpful for me

Thank you

Sadheesh

Wednesday, March 7, 2012

how to implement transactions in sql server 2000

hi,

i have developed an web-enabled database application using ASp.net, C# and sql server 2000.

now i want to implement transaction controls over the same

can anyone plz help me in implementing the same?

thanks in advance

Transaction comes in three part code, the shopping cart, the C# transaction and the stored procs. I would look at the Commerce starter kit but buy Programming .NET by Jeff Prosise it has all the C# code including Session state management. Hope this helps.|||

Hi,

thanx for the suggestion. but i cant find that book over here. Is there any better tutorial whichs online and gives the information abt transactions?

|||

This is the code from the book and I also added link to the Commerce Starter kit it is in VB but you could use that to understand the C# code. Hope this helps.


Congo.aspx
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>

<html>
<body>
<h1>Congo.com</h1>
<form runat="server">
<table width="100%" bgcolor="teal">
<tr>
<td>
<asp:Button Text="View Cart" OnClick="OnViewCart"
RunAt="server" />
</td>
</tr>
</table>
<br>
<center>
<asp:DataGrid ID="MyDataGrid"
AutoGenerateColumns="false" CellPadding="2"
BorderWidth="1" BorderColor="lightgray"
Font-Name="Verdana" Font-Size="8pt"
GridLines="vertical" Width="90%"
OnItemCommand="OnItemCommand" RunAt="server">
<Columns>
<asp:BoundColumn HeaderText="Item ID"
DataField="title_id" />
<asp:BoundColumn HeaderText="Title"
DataField="title" />
<asp:BoundColumn HeaderText="Price"
DataField="price" DataFormatString="{0:c}"
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="right" />
<asp:ButtonColumn HeaderText="Action" Text="Add to Cart"
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="center"
CommandName="AddToCart" />
</Columns>
<HeaderStyle BackColor="teal" ForeColor="white"
Font-Bold="true" />
<ItemStyle BackColor="white" ForeColor="darkblue" />
<AlternatingItemStyle BackColor="beige"
ForeColor="darkblue" />
</asp:DataGrid>
</center>
</form>
</body>
</html>

<script language="C#" runat="server">
void Page_Load (Object sender, EventArgs e)
{
if (!IsPostBack) {
string ConnectString =
ConfigurationSettings.AppSettings["connectString"];
SqlDataAdapter adapter = new SqlDataAdapter
("select * from titles where price != 0", ConnectString);
DataSet ds = new DataSet ();
adapter.Fill (ds);
MyDataGrid.DataSource = ds;
MyDataGrid.DataBind ();
}
}

void OnItemCommand (Object sender, DataGridCommandEventArgs e)
{
if (e.CommandName == "AddToCart") {
BookOrder order = new BookOrder (e.Item.Cells[0].Text,
e.Item.Cells[1].Text, Convert.ToDecimal
(e.Item.Cells[2].Text.Substring (1)), 1);
ShoppingCart cart = (ShoppingCart) Session["MyShoppingCart"];
if (cart != null)
cart.AddOrder (order);
}
}

void OnViewCart (Object sender, EventArgs e)
{
Response.Redirect ("ViewCart.aspx");
}
</script>
ViewCart.aspx
<html>
<body>
<h1>Shopping Cart</h1>
<form runat="server">
<table width="100%" bgcolor="teal">
<tr>
<td>
<asp:Button Text="Return to Shopping" OnClick="OnShop"
RunAt="server" />
</td>
</tr>
</table>
<br>
<center>
<asp:DataGrid ID="MyDataGrid"
AutoGenerateColumns="false" CellPadding="2"
BorderWidth="1" BorderColor="lightgray"
Font-Name="Verdana" Font-Size="8pt"
GridLines="vertical" Width="90%"
OnItemCommand="OnItemCommand" RunAt="server">
<Columns>
<asp:BoundColumn HeaderText="Item ID"
DataField="ItemID" />
<asp:BoundColumn HeaderText="Title"
DataField="Title" />
<asp:BoundColumn HeaderText="Price"
DataField="Price" DataFormatString="{0:c}"
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="right" />
<asp:BoundColumn HeaderText="Quantity"
DataField="Quantity"
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="center" />
<asp:ButtonColumn HeaderText="Action" Text="Remove"
HeaderStyle-HorizontalAlign="center"
ItemStyle-HorizontalAlign="center"
CommandName="RemoveFromCart" />
</Columns>
<HeaderStyle BackColor="teal" ForeColor="white"
Font-Bold="true" />
<ItemStyle BackColor="white" ForeColor="darkblue" />
<AlternatingItemStyle BackColor="beige"
ForeColor="darkblue" />
</asp:DataGrid>
</center>
<h3><asp:Label ID= "Total" RunAt="server" /></h3>
</form>
</body>
</html>

<script language="C#" runat="server">
void Page_Load (Object sender, EventArgs e)
{
ShoppingCart cart = (ShoppingCart) Session["MyShoppingCart"];
if (cart != null) {
MyDataGrid.DataSource = cart.Orders;
MyDataGrid.DataBind ();
Total.Text = String.Format ("Total Cost: {0:c}",
cart.TotalCost);
}
}

void OnItemCommand (Object sender, DataGridCommandEventArgs e)
{
if (e.CommandName == "RemoveFromCart") {
ShoppingCart cart = (ShoppingCart) Session["MyShoppingCart"];
if (cart != null) {
cart.RemoveOrder (e.Item.Cells[0].Text);
MyDataGrid.DataBind ();
Total.Text = String.Format ("Total Cost: {0:c}",
cart.TotalCost);
}
}
}

public void OnShop (Object sender, EventArgs e)
{
Response.Redirect ("Congo.aspx");
}
</script>
Congo.cs
using System;
using System.Collections;

[Serializable]
public class BookOrder
{
string _ItemID;
string _Title;
decimal _Price;
int _Quantity;

public string ItemID
{
get { return _ItemID; }
set { _ItemID = value; }
}

public string Title
{
get { return _Title; }
set { _Title = value; }
}

public decimal Price
{
get { return _Price; }
set { _Price = value; }
}

public int Quantity
{
get { return _Quantity; }
set { _Quantity = value; }
}

public BookOrder (string ItemID, string Title, decimal Price,
int Quantity)
{
_ItemID = ItemID;
_Title = Title;
_Price = Price;
_Quantity = Quantity;
}
}

[Serializable]
public class ShoppingCart
{
Hashtable _Orders = new Hashtable ();

public ICollection Orders
{
get { return _Orders.Values; }
}

public decimal TotalCost
{
get
{
decimal total = 0;
foreach (DictionaryEntry entry in _Orders) {
BookOrder order = (BookOrder) entry.Value;
total += (order.Price * order.Quantity);
}
return total;
}
}

public void AddOrder (BookOrder Order)
{
BookOrder order = (BookOrder) _Orders[Order.ItemID];
if (order != null)
order.Quantity += Order.Quantity;
else
_Orders.Add (Order.ItemID, Order);
}

public void RemoveOrder (string ItemID)
{
if (_Orders[ItemID] != null)
_Orders.Remove (ItemID);
}
}


http://asp.net/CommerceStarterKit/docs/docs.htm

|||

It's not a book. "Starter Kit"

http://asp.net/Default.aspx?tabindex=8&tabid=47

How To Implement sql server database on the client's computer?

Hello,
I finished my vb.net application, the application uses sql server and run pretty well on my pc. Now I want to install this application on the customer's computer, and the issue I'm not sure about is, what do I need to install on the client's computer concerning the database?
Do I install SQL Server and restore the database there? how to secure the database and make sure nobody will be able to edit the data from Enterprise Manager. What if someone uninstalled SQL Server?

Please I need help in this issue since I'm a beginner.

Thanks.

Quote:

Originally Posted by Tea Maker

Hello,
I finished my vb.net application, the application uses sql server and run pretty well on my pc. Now I want to install this application on the customer's computer, and the issue I'm not sure about is, what do I need to install on the client's computer concerning the database?
Do I install SQL Server and restore the database there? how to secure the database and make sure nobody will be able to edit the data from Enterprise Manager. What if someone uninstalled SQL Server?

Please I need help in this issue since I'm a beginner.

Thanks.


You will need to install SQL Server on your customer's server (or just his/her computer if they're the only person that will be using it). As for security, you'll need to set up database users and set their permissions accordingly. Obviously you'll need to change your app to reflect the change of database location.|||

Quote:

Originally Posted by DonlonP

You will need to install SQL Server on your customer's server (or just his/her computer if they're the only person that will be using it). As for security, you'll need to set up database users and set their permissions accordingly. Obviously you'll need to change your app to reflect the change of database location.


If I set users permissions then nobody will be able to open the database? because I've tried this before, but anyone can access the database through Enterprise Manager without username and password? And what about if someone uninstalled sql server?
I'll be thanksfull if you provide me some links where I can read articles about this issue because I couldn't find any related articles.

Thanks|||

Quote:

Originally Posted by Tea Maker

If I set users permissions then nobody will be able to open the database? because I've tried this before, but anyone can access the database through Enterprise Manager without username and password? And what about if someone uninstalled sql server?
I'll be thanksfull if you provide me some links where I can read articles about this issue because I couldn't find any related articles.

Thanks


On second thoughts you don't even need to set user permissions if you install SQL Server 2000 desktop edition (which is free!) this doesn't come with enterprise manager anyway. Download from:
http://www.microsoft.com/downloads/...&displaylang=en
Obviously if someone uninstalled SQL Server then you wouldn't have a database and your app wouldn't work, and the person who uninstalled it would be a complete muppet!|||

Quote:

Originally Posted by DonlonP

On second thoughts you don't even need to set user permissions if you install SQL Server 2000 desktop edition (which is free!) this doesn't come with enterprise manager anyway. Download from:
http://www.microsoft.com/downloads/...&displaylang=en
Obviously if someone uninstalled SQL Server then you wouldn't have a database and your app wouldn't work, and the person who uninstalled it would be a complete muppet!


Wow, Thanks alot that helped me out so much.
Just one more question, How can I transfer the database from my computer to the other, do I create a backup and restore it there? and where do I place my databases.

How to implement Database Mirroring with SQL2000

Hi,
Our client is located in Europe region. Our application was a web based
application using SQL Server 2000 database as the back-end, where this server
was located in Europe region. All the users will visit this site through out
the world.
Now the client was observing some performance problems in their offices in
Asia region. The reason seems to be a relatively bad connection between
Europe and Asia. The available bandwidth should be by far sufficient (10
Mbit/s), but the latency seems to be too slow (approx. 350 ms). Our Client is
checking with other providers, but they may have similar problems. The effect
is that the measured response times in their Asian office are too long
(typically 3 – 5 seconds). Their target is to get response times below 2
seconds to make sure that the users can work efficiently.
One possible solution which has been suggested to us was that to install the
web based application also on a server in the Asian office. There would be 2
mirrored databases with the same data. The users in Asia would access this
server, whereas the users in Europe and America would access the server in
Europe. Probably it would be sufficient to update the data once a day or even
less frequently.
Does SQL Server 2000 support such a solution? Do you think this would be a
feasible solution? If this solution should be implemented, how should we
proceed?
Or else Can you suggest any other solution?
Thanks and Regards
ourspt
ourspt
> Does SQL Server 2000 support such a solution? Do you think this would be a
> feasible solution? If this solution should be implemented, how should we
> proceed?
Yes it does. It could be SNAPSHOT Replication to update tthe database or
just simple BACKUP and RESTORE database
But regarding to where the server should be located it is your decision and
do some testing
http://www.mssqlcity.com/Articles/Replic/Replic.htm --Setting All
Replica (Step by step)
"ourspt" <ourspt@.discussions.microsoft.com> wrote in message
news:BAA5A573-735B-449F-90BD-9DB6A54D3D10@.microsoft.com...
> Hi,
> Our client is located in Europe region. Our application was a web based
> application using SQL Server 2000 database as the back-end, where this
> server
> was located in Europe region. All the users will visit this site through
> out
> the world.
> Now the client was observing some performance problems in their offices in
> Asia region. The reason seems to be a relatively bad connection between
> Europe and Asia. The available bandwidth should be by far sufficient (10
> Mbit/s), but the latency seems to be too slow (approx. 350 ms). Our Client
> is
> checking with other providers, but they may have similar problems. The
> effect
> is that the measured response times in their Asian office are too long
> (typically 3 5 seconds). Their target is to get response times below 2
> seconds to make sure that the users can work efficiently.
> One possible solution which has been suggested to us was that to install
> the
> web based application also on a server in the Asian office. There would be
> 2
> mirrored databases with the same data. The users in Asia would access this
> server, whereas the users in Europe and America would access the server in
> Europe. Probably it would be sufficient to update the data once a day or
> even
> less frequently.
> Does SQL Server 2000 support such a solution? Do you think this would be a
> feasible solution? If this solution should be implemented, how should we
> proceed?
> Or else Can you suggest any other solution?
> Thanks and Regards
> --
> ourspt

How to implement Database Mirroring with SQL2000

Hi,
Our client is located in Europe region. Our application was a web based
application using SQL Server 2000 database as the back-end, where this serve
r
was located in Europe region. All the users will visit this site through out
the world.
Now the client was observing some performance problems in their offices in
Asia region. The reason seems to be a relatively bad connection between
Europe and Asia. The available bandwidth should be by far sufficient (10
Mbit/s), but the latency seems to be too slow (approx. 350 ms). Our Client i
s
checking with other providers, but they may have similar problems. The effec
t
is that the measured response times in their Asian office are too long
(typically 3 – 5 seconds). Their target is to get response times below 2
seconds to make sure that the users can work efficiently.
One possible solution which has been suggested to us was that to install the
web based application also on a server in the Asian office. There would be 2
mirrored databases with the same data. The users in Asia would access this
server, whereas the users in Europe and America would access the server in
Europe. Probably it would be sufficient to update the data once a day or eve
n
less frequently.
Does SQL Server 2000 support such a solution? Do you think this would be a
feasible solution? If this solution should be implemented, how should we
proceed?
Or else Can you suggest any other solution?
Thanks and Regards
--
oursptourspt
> Does SQL Server 2000 support such a solution? Do you think this would be a
> feasible solution? If this solution should be implemented, how should we
> proceed?
Yes it does. It could be SNAPSHOT Replication to update tthe database or
just simple BACKUP and RESTORE database
But regarding to where the server should be located it is your decision and
do some testing
http://www.mssqlcity.com/Articles/Replic/Replic.htm --Setting All
Replica (Step by step)
"ourspt" <ourspt@.discussions.microsoft.com> wrote in message
news:BAA5A573-735B-449F-90BD-9DB6A54D3D10@.microsoft.com...
> Hi,
> Our client is located in Europe region. Our application was a web based
> application using SQL Server 2000 database as the back-end, where this
> server
> was located in Europe region. All the users will visit this site through
> out
> the world.
> Now the client was observing some performance problems in their offices in
> Asia region. The reason seems to be a relatively bad connection between
> Europe and Asia. The available bandwidth should be by far sufficient (10
> Mbit/s), but the latency seems to be too slow (approx. 350 ms). Our Client
> is
> checking with other providers, but they may have similar problems. The
> effect
> is that the measured response times in their Asian office are too long
> (typically 3 5 seconds). Their target is to get response times below 2
> seconds to make sure that the users can work efficiently.
> One possible solution which has been suggested to us was that to install
> the
> web based application also on a server in the Asian office. There would be
> 2
> mirrored databases with the same data. The users in Asia would access this
> server, whereas the users in Europe and America would access the server in
> Europe. Probably it would be sufficient to update the data once a day or
> even
> less frequently.
> Does SQL Server 2000 support such a solution? Do you think this would be a
> feasible solution? If this solution should be implemented, how should we
> proceed?
> Or else Can you suggest any other solution?
> Thanks and Regards
> --
> ourspt

How to implement Database Mirroring with SQL2000

Hi,
Our client is located in Europe region. Our application was a web based
application using SQL Server 2000 database as the back-end, where this server
was located in Europe region. All the users will visit this site through out
the world.
Now the client was observing some performance problems in their offices in
Asia region. The reason seems to be a relatively bad connection between
Europe and Asia. The available bandwidth should be by far sufficient (10
Mbit/s), but the latency seems to be too slow (approx. 350 ms). Our Client is
checking with other providers, but they may have similar problems. The effect
is that the measured response times in their Asian office are too long
(typically 3 â' 5 seconds). Their target is to get response times below 2
seconds to make sure that the users can work efficiently.
One possible solution which has been suggested to us was that to install the
web based application also on a server in the Asian office. There would be 2
mirrored databases with the same data. The users in Asia would access this
server, whereas the users in Europe and America would access the server in
Europe. Probably it would be sufficient to update the data once a day or even
less frequently.
Does SQL Server 2000 support such a solution? Do you think this would be a
feasible solution? If this solution should be implemented, how should we
proceed?
Or else Can you suggest any other solution?
Thanks and Regards
--
oursptourspt
> Does SQL Server 2000 support such a solution? Do you think this would be a
> feasible solution? If this solution should be implemented, how should we
> proceed?
Yes it does. It could be SNAPSHOT Replication to update tthe database or
just simple BACKUP and RESTORE database
But regarding to where the server should be located it is your decision and
do some testing
http://www.mssqlcity.com/Articles/Replic/Replic.htm --Setting All
Replica (Step by step)
"ourspt" <ourspt@.discussions.microsoft.com> wrote in message
news:BAA5A573-735B-449F-90BD-9DB6A54D3D10@.microsoft.com...
> Hi,
> Our client is located in Europe region. Our application was a web based
> application using SQL Server 2000 database as the back-end, where this
> server
> was located in Europe region. All the users will visit this site through
> out
> the world.
> Now the client was observing some performance problems in their offices in
> Asia region. The reason seems to be a relatively bad connection between
> Europe and Asia. The available bandwidth should be by far sufficient (10
> Mbit/s), but the latency seems to be too slow (approx. 350 ms). Our Client
> is
> checking with other providers, but they may have similar problems. The
> effect
> is that the measured response times in their Asian office are too long
> (typically 3 ? 5 seconds). Their target is to get response times below 2
> seconds to make sure that the users can work efficiently.
> One possible solution which has been suggested to us was that to install
> the
> web based application also on a server in the Asian office. There would be
> 2
> mirrored databases with the same data. The users in Asia would access this
> server, whereas the users in Europe and America would access the server in
> Europe. Probably it would be sufficient to update the data once a day or
> even
> less frequently.
> Does SQL Server 2000 support such a solution? Do you think this would be a
> feasible solution? If this solution should be implemented, how should we
> proceed?
> Or else Can you suggest any other solution?
> Thanks and Regards
> --
> ourspt

Friday, February 24, 2012

How to implement Application Roles for an application?

I want to know how to implement Application Roles for an application which
uses mutliple databases. Based on what I have read, Application Roles are
tied to one database only and accessing other databases requires adding gues
t
user account to other databases. For example, if an application is using on
e
database to contain access rights data to its functions and another database
for actual transaction data, how can I implement Application Role?
Thanks.Your understanding is correct; once an application role is activated, other
databases can be accessed only via the guest user security context.
If you don't want to grant permissions to guest or public in the other
databases, consider creating referencing views or procs in your application
role database and enabling cross-database chaining in the databases
involved. As long as the objects involved have the same owner, permissions
are not needed on indirectly referenced objects. Note that the databases
also need to be owned by the same login in order to maintain an unbroken
ownership chain for dbo-owned objects.
You should enable cross-database chaining only if you fully understand the
security implications. See the Books Online
<instsql.chm::/in_runsetup_1cj5.htm> for more information.
Hope this helps.
Dan Guzman
SQL Server MVP
"Peter" <Peter@.discussions.microsoft.com> wrote in message
news:36AC8304-5158-4335-B1C4-B503F51E3F43@.microsoft.com...
>I want to know how to implement Application Roles for an application which
> uses mutliple databases. Based on what I have read, Application Roles are
> tied to one database only and accessing other databases requires adding
> guest
> user account to other databases. For example, if an application is using
> one
> database to contain access rights data to its functions and another
> database
> for actual transaction data, how can I implement Application Role?
>
> Thanks.|||Hi Dan,
Can you elaborate little bit more about referencing views and procedure?
My understanding of Application role:
1. It is connection-based (session-based).
2. It needs to be activated by using sp_setapprole.
3. By default, application role has no permission on the databases. So,
permissions need to be assigned to the role.
I'm trying to develop an application which can connect to SQL Server using
either SQL Authentication or Windows Authentication through ODBC. The
administrator(s) of the application can configure whether the databases
created by the application can be accessed by other applications (this is wh
y
I'm looking at application role). The application is using multiple
databases per connection/session.
Thanks,
Peter
"Dan Guzman" wrote:

> Your understanding is correct; once an application role is activated, othe
r
> databases can be accessed only via the guest user security context.
> If you don't want to grant permissions to guest or public in the other
> databases, consider creating referencing views or procs in your applicatio
n
> role database and enabling cross-database chaining in the databases
> involved. As long as the objects involved have the same owner, permission
s
> are not needed on indirectly referenced objects. Note that the databases
> also need to be owned by the same login in order to maintain an unbroken
> ownership chain for dbo-owned objects.
> You should enable cross-database chaining only if you fully understand the
> security implications. See the Books Online
> <instsql.chm::/in_runsetup_1cj5.htm> for more information.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "Peter" <Peter@.discussions.microsoft.com> wrote in message
> news:36AC8304-5158-4335-B1C4-B503F51E3F43@.microsoft.com...
>
>|||> Can you elaborate little bit more about referencing views and procedure?
You can create views and/or procs in your application role database that
reference those objects in other databases needed by your application. For
example:
USE MyAppRoleDatabase
GO
CREATE VIEW dbo.MyView
AS
SELECT SomeData
FROM MyOtherDatabase.dbo.MyTable
GO
GRANT ALL ON dbo.MyView TO MyAppRole
GO
As long as MyAppRoleDatabase and MyOtherDatabase are owned by the same
login, the ownership chain for dbo-owned objects is unbroken. This allows
the application role to access MyTable data via MyView even without
permissions the underlying table. As mentioned earlier in this thread, the
guest user needs to be enabled in MyOtherDatabase in order to establish a
security context for the application role.

> 3. By default, application role has no permission on the databases. So,
> permissions need to be assigned to the role.
This is true but note that permissions are needed only on the objects
*directly* referenced by the role. Permissions are not checked on
indirectly referenced objects as long as the ownership chain is unbroken.

> I'm trying to develop an application which can connect to SQL Server using
> either SQL Authentication or Windows Authentication through ODBC.
Application roles can be used with either authentication method.

> The administrator(s) of the application can configure whether the
> databases
> created by the application can be accessed by other applications (this is
> why
> I'm looking at application role).
Are you saying that you have multiple applications and application roles?
In this case, each application role database would need referencing objects
as described above.
Hope this helps.
Dan Guzman
SQL Server MVP
"Peter" <Peter@.discussions.microsoft.com> wrote in message
news:6362673A-F318-429B-946A-FC66BFA2D490@.microsoft.com...[vbcol=seagreen]
> Hi Dan,
> Can you elaborate little bit more about referencing views and procedure?
> My understanding of Application role:
> 1. It is connection-based (session-based).
> 2. It needs to be activated by using sp_setapprole.
> 3. By default, application role has no permission on the databases. So,
> permissions need to be assigned to the role.
> I'm trying to develop an application which can connect to SQL Server using
> either SQL Authentication or Windows Authentication through ODBC. The
> administrator(s) of the application can configure whether the databases
> created by the application can be accessed by other applications (this is
> why
> I'm looking at application role). The application is using multiple
> databases per connection/session.
>
> Thanks,
> Peter
>
> "Dan Guzman" wrote:
>

How to impersonate the user and send those credentials?

I want to create only one user on the domain, and my application should send that user and password to the reportviewer, in that way I wont have to give permissions to every user individually .

Does anyone have the lines of code to do this?

Check the WindowsIdentity class (particularly WindowsIdentity.Impersonate): http://msdn2.microsoft.com/en-us/library/system.security.principal.windowsidentity(VS.80).aspx

-- Robert