Link to home
Start Free TrialLog in
Avatar of e106199
e106199Flag for United States of America

asked on

Visial Studio 2003 problem

Hi all,
i have problem and i dont know if its a limitation or a bug in visual studio. I am using asp.net with vb.net on an xp pro and visual studio 2003.
The problem is; when i oledbdataadapter in my web form the connection string is automatically created with it. But i want to use server.mappath in my connection string and the dataadapter wizard wont let this. So i m changing the connectionstring in codebehind but i m getting an error. Error doesnt effect anything and the page runs with no problem but anytime i change someting in the page design (adding a label or deleting a label...) the connection string clears out. If i configure it the way visual studio wants there is no problem.

My question is: is there  a way to set the connectionstring property with server.mappath in design time or is there a way to stop visual studio clearing my custom string after something changes in the page? I can finalize everthing and then change the connection string to my custom string and build my application but i want to know if there is another proper way for this.

any help will be appreciated.
thanks,
-shane
Avatar of BurntSky
BurntSky

The reason VS.NET keeps clearing your connection string is because you wrote it in the Designer Generated code area (the block of code it explicitly says not to touch).  The reason you're not supposed to touch anything there is because the designer constantly rewrites this code, therefore erasing any changes you made.

What you can do to solve this is to set the connection string at runtime (in the Page.Load event or even right before you connect your adapter.)
Avatar of e106199

ASKER

Hi,
i have all my dataadapter and insert/update/delete commands in designer generated code area.So setting the connection string in page load wont be a problem since all the commands are using the connectiong string to do what they are supposed to do right?
thanks,
-shane
ASKER CERTIFIED SOLUTION
Avatar of BurntSky
BurntSky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of e106199

ASKER

thanks,
i wish visual studio supported server.mappath method but this information is enough for now.
thanks,
-shane
Avatar of e106199

ASKER

BurntSky,
i m still having problems with the design time connection element.
Here is the real scenerion: i have a grid and its datasource is a dataset which is populated by a dataadapter. All dataadapter and dataset are created in design time by Visual Studio. I have an access db so Visual studio created a connection string that uses the full path of the db file. (i dont know if its possible to tell it use a relative path).
I deleted the connection string created by visual studio and created my own in page_load event. But the select command needs this connection string to populate the grid elements and its giving me the following error message;
Fill: SelectCommand.Connection property has not been initialized.

Do you think i should keep the connection string created by visual studio and set its value to my value in run time?

Or the real solution of my problem is: Can i use relative path in connection string while letting visual studio create it for me?

thanks,
-shane
Honestly, I know it's not the answer you want to hear, but I think you're SOL for the design time issue.  Keep the connection string VS.NET generates for you and then override it at runtime.  Personally, I've always hated how finicky the VS.NET designer is and I just code everything by hand.
Avatar of e106199

ASKER

Thanks,
thats what i do now. The designer is saving a lot of time but i wish it was more flexible.
-shane
Believe me, I know how you feel.  Hopefully the little issues like this will be fixed in VS.NET 2005.