Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 How to declare database connection in a module

Author  Topic 

Mamatha
Posting Yak Master

102 Posts

Posted - 2005-10-19 : 14:21:59
Hi
I am designing a small application with 4 or 5 forms in VB.NET.
Now i want to store my data in a database,so i had declared a database connection in a module and try to call that module function from a form.But it gives error when i am declaring con object in a module.
"Error was con object not declared" but i declared con and imported SQLclient also in that module.
Why i got this type of error?
How can i declare a database in a module?and how can i call that module from a form?
Please give me any solution for this.

Thanks
Mamatha



Mamatha

Kristen
Test

22859 Posts

Posted - 2005-10-19 : 14:45:47
If you need some guidance on getting your connection string correct have a look here:

www.connectionstrings.com

otherwise you probably need to post the code you are testing here so that folk can comment on it

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-20 : 02:03:49
In VB.NET you can use sqlconnection data from Tool box and connect to SQL Server
Then copy the ConnectionString and use that in your code

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2005-10-20 : 08:35:59
I know this is a crazy thought, but do you think if you showed us some of your code (your module declaration of the connection, how you initialize it, how you are accessing it) it might be a little bit easier for us to help you?
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-10-20 : 10:10:10
You can declare the connection string as a constant at the module level.

But my suggestion would be to create a db layer class where your string could be encapsulated
into its own db class. Your forms should only know about creating a database object and calling an open function, the details of how it is done is hidden to other application developers.

It's a bit more work, but reusable.

Jon



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]
Imperfection living for perfection --
[url]http://jhermiz.blogspot.com/[/url]
Go to Top of Page

karuna
Aged Yak Warrior

582 Posts

Posted - 2005-10-20 : 10:59:52

How about storing connection string in the App.Config?

Thanks


Karunakaran
Go to Top of Page
   

- Advertisement -