1

Changing Sql Connection dynamically in Crystal Reports 10 using DotNet

by Syed Aziz ur Rahman 20. July 2004 01:12

Dim

myReport As New crDB()
myReport.SetDatabaseLogon(Me.txtUserId.Text, Me.txtPass.Text, Me.txtServer.Text, Me.txtDB.Text)
Dim myLogonInfo As CrystalDecisions.Shared.TableLogOnInfo
Dim myTable As CrystalDecisions.CrystalReports.Engine.Table

For
Each myTable In myReport.Database.Tables
   myLogonInfo = myTable.LogOnInfo
   With myLogonInfo.ConnectionInfo
      .ServerName = Me.txtServer.Text
      .DatabaseName = Me.txtDB.Text
      .UserID = Me.txtUserId.Text
      .Password = Me.txtPass.Text
  End With

   Try
     
myTable.ApplyLogOnInfo(myLogonInfo)
   Catch
     
MessageBox.Show("Login Failed")
      Exit
Sub
   End Try

   'Note: The next line is only necessary for SQL Server
  
myTable.Location = myTable.Location.Substring(myTable.Location.LastIndexOf(".") + 1)
Next myTable
CrystalReportViewer1.ReportSource = myReport

A very important piece of code is the assignment of the myTable.Location property (near the end of the listing). A requirement for changing the data source of a SQL Server table is that you must also change the Location property of the Table object. The Location property is a string value that has the name of the server as part of the string. It lists the database name, the table owner and the table name. For example, it looks similar to the following:

pubs.dbo.Customers

If you leave the Location property alone and don?t overwrite it, then the report?s server and database name won?t change. Instead, you have to reset it to just the table name. By removing the database name from the string, the report has to look at the new properties you just set to get this information. Consequently, this results in the server and database changing.

The easiest change to make would be to overwrite the Location property with a string constant. For example, the following line of code would overwrite it with the ?Customers? table.

myTable.Location = "Customers"

This works fine if the report only uses one table. But when you have multiple tables, you have to get more creative because you can?t assign the same table name to every table object. Rather than use a string constant, the code parses out the table name from the Location property and reassigns it to itself. This has the effect of resetting the value, but dropping the database name and table owner from the string.

myTable.Location = myTable.Location.Substring(myTable.Location.LastIndexOf(".") + 1)

HTH

 

 

Tags:

ASP.Net | DotNet | SqlServer

Comments (1) -

agen pulsa nasional
agen pulsa nasional
8/16/2013 4:39:13 PM #

The three owners had enough faith in the people and what we were doing to think we could make a difference and treat them differently. I have a base station here shown by a tower. And it was a theoretical result and it would take several decades for experimental physicists to prove the existence of electromagnetic waves and what you end up using.

Have a look at my website ::  agen pulsa nasional - http://www.youtube.com/watch?v=KR0dvfYs_GI

voyance gratuite immediate
voyance gratuite immediate
8/20/2013 10:33:45 AM #

Signe astrologique 6 mai internaute magazine horoscope

Here is my website ...  voyance gratuite immediate - http://www.foryou-wasserbett.com

Keuntungan Bisnis Pulsa
Keuntungan Bisnis Pulsa
8/21/2013 4:50:42 AM #

So I put exactly this cluster telecommunications jobs on long island of 7 cells nearby. The reverse voice channel is used for voice transmission from the mobile to the base station.

my web-site;  Keuntungan Bisnis Pulsa - http://www.youtube.com/watch?v=PS3CTD-TPQs

Sarah
Sarah
8/22/2013 2:08:49 AM #

Hi there very cool site!! Guy .. Excellent .. Amazing .. I'll bookmark your website and take the feeds also? I am satisfied to seek out a lot of useful info right here within the put up, we'd like work out extra strategies in this regard, thanks for sharing. . . . . .

Here is my web blog: ICD 9 Opioidabhangigkeit -  Sarah - http://newmyshopblog.com/kaufen_revia_online_de_1/  -

rent game servers
rent game servers
8/24/2013 2:48:27 PM #

Online gaming requires a network that includes solitary or more computers to work as servers. The computers of the players are termed as clients. Clients link to the server through the Internet or a local network. The server acts like an organization of the net gaming that keeps track with selected game of player, keeps records of player and also provides gossip between players.
The gaming servers work just like your average web server. Just that, instead of hosting websites, these special servers host computer games that users can join and play. The crucial information related to gaming, like the scores and the rules of the game are in the server and are accessed from there as well. The gamers just log on and play the game that attracts them most.
Bandwidth is important to any business website. This relates to the number of customers who can visit your site at one time. You naturally never want to limit your traffic flow to your website, but if you are using a gamer shared server, you are probably doing that already. Because the shared server can only accommodate so much traffic, some of your customers may be experiencing trouble logging on to your website.
The modern advancements include, new skins, quicker gameplay, enhanced maps, much more items and many of 3rd party plugins and addons towards the game.
While in a distributed system, server software stores numerous excited  game servers - http://hfgameservers.co.uk/  on clients' PCs. Instantaneous strategy is used in games such as Myth and 3D shooters like Quake III Arena etc. These games need very prompt updates known as "state of the world". Distributed servers extend the pack of communication out; a solitary server hardly keeps up with numerous Quake players.
Non-player controlled characters. These characters are very important to the MMORPG world because they serve as merchants, stores, auction houses, quest givers, and more.
The sound quality of the Ventrilo Voice Server program is similar to a conference call over the phone line and is dependent on the user's internet connection, speaker/headset quality, and microphone quality. Many users choose to download the Ventrilo Voice Server software because the program does not use many CPU resources and is available as a free program as long as no more than eight people want to talk.
The current breakthroughs contain, new skins, more rapidly gameplay, improved maps, more objects and lots of of third celebration plugins and addons to the game.

voyant gratuit
voyant gratuit
8/24/2013 6:55:03 PM #

Horoscope feng shui horoscope du taureau 2012

Feel free to visit my web-site ...  voyant gratuit - http://www.moeys-elibrary.org

medium gratuit
medium gratuit
8/25/2013 1:57:11 AM #

Tirage du tarot gratuit marie claire horoscope 2012 mois par mois gratuit

Here is my site:  medium gratuit - http://www.moeys-elibrary.org

voyant gratuit
voyant gratuit
8/26/2013 1:42:50 PM #

Vraiment gratuit compatibilite signe astrologique

Also visit my site ::  voyant gratuit - http://www.monvoyant.org

voyance en ligne gratuite
voyance en ligne gratuite
8/28/2013 7:07:09 PM #

Tarot marseille gratuit en ligne tarot en ligne gratuit sans inscription

my page ...  voyance en ligne gratuite - http://www.discovergrandcanyontours.com

voyance gratuite immediate
voyance gratuite immediate
8/30/2013 10:19:16 AM #

La cartomancie direct voyance

Review my website:  voyance gratuite immediate - http://Discovergrandcanyontours.com

Www.countrysportscentre.com
Www.countrysportscentre.com
8/30/2013 10:20:45 PM #

Tarot gratuit online cartomancie gratuite reponse par oui ou non

my site voyance gratuite immediate -  Www.countrysportscentre.com - http://Www.countrysportscentre.com/  -

voyance gratuite en direct
voyance gratuite en direct
8/31/2013 10:23:32 AM #

Signes astrologiques elements cartomancie en ligne gratuit

Look into my web-site -  voyance gratuite en direct - http://www.countrysportscentre.com

voyance gratuite En ligne
voyance gratuite En ligne
8/31/2013 9:50:10 PM #

Horoscope scorpion du jour oracles gratuit

Feel free to surf to my weblog:  voyance gratuite En ligne - http://www.discovergrandcanyontours.com

Voyance en ligne Gratuite
Voyance en ligne Gratuite
9/1/2013 4:37:09 PM #

Mon signe astrologique japonais tatoo signe astrologique

my web-site ::  Voyance en ligne Gratuite - http://www.discovergrandcanyontours.com

www.discovergrandcanyontours.com
www.discovergrandcanyontours.com
9/2/2013 1:15:17 AM #

Astrologie tirage persan amour

Here is my weblog - voyance en direct ( www.discovergrandcanyontours.com - http://www.discovergrandcanyontours.com )

jual voucher game online
jual voucher game online
9/2/2013 8:12:08 AM #

You can play fun games, have great activities, and do things like play cards or simply enjoy your time with other families. In Assassin's Creed, MPC's have been found to have a number of different Sonic games to game online 6 make one massive Sonic Experience. If the random number generator even game online 6 before the game has had the chance to load. Your uncle's marrying one of the players.

Here is my webpage:  jual voucher game online - http://www.youtube.com/watch?v=vmXnw-C-UZU

Kellie
Kellie
9/10/2013 11:51:20 PM #

you're really a excellent webmaster. The website loading speed is amazing. It kind of feels that you are doing any distinctive trick. Moreover, The contents are masterpiece. you have performed a magnificent process on this topic!

Also visit my site web design service ( Kellie - http://ecomm-max.com/ )

reproduction dining furniture
reproduction dining furniture
9/23/2013 2:53:14 AM #

This post is actually a nice one it helps new web people, who are wishing for blogging.

Here is my webpage -  reproduction dining furniture - parklanefurniture.co.uk/...duction-sideboards.html

pertanian kelapa sawit
pertanian kelapa sawit
9/24/2013 1:49:29 AM #

Then you can help reduce greenhouse emissions take place as a machine lubricant. Today, palm oil definition what has been doubled. To really control for factors, including rising interest from the Scouts' cookies or to use it? Your skin is known as" feedstock" for power stations are coming from.

Here is my web page  pertanian kelapa sawit - http://www.youtube.com/watch?v=8KuWCfY-1Xg

investasi kebun sawit
investasi kebun sawit
9/25/2013 12:21:46 PM #

Hello friends, I'm putting the pepper, ukpaka and diced onion in the Nigerian Nkwobi video. Well, let's go ahead and go," Oh the music is palm oil united states playing, don't have a relevant interest. Things you already know, like, antioxidants and beta-carotene, which was blinded in one in every one of individual liberty, so avoid these completely. But sometimes palm oil united states we need to cover the beans is cooking, slice the onion rings.

Here is my webpage;  investasi kebun sawit - http://www.investasikelapasawit.com

investasi lahan sawit
investasi lahan sawit
10/8/2013 12:10:22 AM #

Palm oil contributes saturated fats, actually helps to improve 3rd palm oil summit your cholesterol profile. But, it's humans who are clear-cutting Kesi's rainforest habitat in Indonesia and Malaysia, where the widely used edible oil is often found in biscuits, cooking oils and margarines, according to the American Heart Association. The saturated fat could be deadly for your parrot.

my blog post  investasi lahan sawit - http://www.investasikelapasawit.com

agen pulsa elektrik murah
agen pulsa elektrik murah
10/13/2013 11:31:21 AM #

Let's review our large fiber-to-the-X projects, which agen pulsa all operator I believe are well-known to many, if not the fastest-growing area in the semiconductor space. Michael I Rollins Citigroup You mentioned that there was some splashing correction as far as within HPMS?

Feel free to surf to my webpage;  agen pulsa elektrik murah - http://www.youtube.com/watch?v=cP2Ir1mn8x0

Oriental Rug Cleaning Passaic NJ
Oriental Rug Cleaning Passaic NJ
10/21/2013 9:51:22 AM #

Take time to write a few and try them out on some friends or associates. The only cleaning component used is heat that is produced by the steam. Gravel is the least hassle for cleaning; all you can do is be sure that you have used an edged stone instead of rounded gravel so that it locks together and stays in place better.

My page ...  Oriental Rug Cleaning Passaic NJ - http://www.youtube.com/watch?v=Hd56ZeJcBOE

have a peek here
have a peek here
10/30/2013 7:12:45 PM #

My brother recommended I would possibly like this web site. He was entirely right. This submit truly made my day. You can not consider just how so much time I had spent for this info! Thank you!

my webpage ::  have a peek here - http://stellaanne82.tumblr.com/

obtenir des gemmes Clash of clans
obtenir des gemmes Clash of clans
11/24/2013 11:11:59 PM #

The i - Phone a few and cheaper iphone rumors have been awfully hot lately, still it will usually the 5S that the majority of leads the way for Apple path of its next version. No, no, the molten gold eventually forms into a gold i - Phone 5s. A lot of speculation has come from both analysts and the Apple community about what features and specs the handset will have.

My web page ...  obtenir des gemmes Clash of clans - http://www.youtube.com/watch?v=DLXJu7fCwu0

mens Designer jeans
mens Designer jeans
12/1/2013 1:40:59 PM #

Yes! Finally someone writes about long women denim skirts.

my weblog;  mens Designer jeans - www.swallowingamoose.com/.../

Powered by BlogEngine.NET 2.5.0.6
Original Design by Laptop Geek, Adapted by onesoft