connecting to a database

adodb , connect , database , path Saint-Denis, France
  • 8 years ago
    I have a question that i would like some help. I normally use ADODB to connect to access db. The problem is that i have to create a connection in every form module including the full path of the database in my PC. If i happen to change the db path then it would mean i have to alter all my connections in the database. i would like to know if their is a better way that i can use to create my connection only once in my application to make things easier.
  • 8 years ago
    hi, You can store your connection string in a Database Table Field. else you can also store the same in your web.config, if you are working on a web application. And you can call it where ever you want. Regards, Royal
  • 8 years ago
    That's sounds complex for me, would you mind an example please?
  • 8 years ago
    Hi Is this web or windows based? DotNet? I use connections to SQLServer and store the details in an XML config file. There are various ways to store and retrieve the information, but it makes it easy to change the details as no code changes are required.
  • 8 years ago
    It is not a web based application, it's a standalone vb6 application.
  • 8 years ago
    ' Set properties of the DataGrid control. Me.DataGrid1.AllowAddNew = False Me.DataGrid1.AllowDelete = False Me.DataGrid1.AllowUpdate = False ' Set properties of the AOD Data Control. Me.Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\DB2.mdb" Me.Adodc1.RecordSource = "SELECT * FROM House" 'Link the DataGrid control to the AOD Data control. Set Me.DataGrid1.DataSource = Me.Adodc1 that is the code i use to conntect a database using a ADOC
  • 8 years ago
    hi depash 1. create one method in another page(which gives connection string) 2. create object to that page .... 3. when ever u want call that method through this object.............. 4. some thing like this................... this is in vb.net page1: your page where u want to access databse ---some code--- dim obj as page2 dim conString as connectionString obj =new page2 //creating object constring=page2.getConnectionString() page2: //vb file class page2 begin public function getConnectionString() as string dim str as string="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" \DB2.mdb" return str end function End i hope this helps
  • 8 years ago
    put the following code in a module and replace databaseName with your database. In every form you want to connect to database just **call connectDatabase** and use your record set to manipulate your data. Public cnn As Connection Public rs As Recordset --------------------------------------------------------------------- Public Sub connectDatabase() Set cnn = New ADODB.Connection With cnn .Provider = "Microsoft.JET.OLEDB.4.0" .ConnectionString = App.Path & "\databaseName.mdb" .Open End With End Sub
  • 8 years ago
    Thanks alot all of you, i used your suggestions and now i connect using the CALL statement which is what i just needed. You are an asset to me.
  • 8 years ago
    web config [paslanmaz](http://www.paslanmazbul.net/) [evden eve nakliyat](http://www.evdenevenakliyatbul.com/) [bul](http://www.paslanmazbul.net/)
  • 8 years ago
    web config
  • 8 years ago
    error post you page
  • 8 years ago
    error post you page

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“We better hurry up and start coding, there are going to be a lot of bugs to fix.”