Sql Connection1
-
I am using sqlconnection control in vb.net and i use it for different form. Everytime if i move my database and my application to other Computer, I need to change the connection string one by one in each form and of course this is abit troublesome for me. Any ways to change the sqlconnection string in properties only 'once', and all sqlconnection string in all forms will also change?
-
I am using sqlconnection control in vb.net and i use it for different form. Everytime if i move my database and my application to other Computer, I need to change the connection string one by one in each form and of course this is abit troublesome for me. Any ways to change the sqlconnection string in properties only 'once', and all sqlconnection string in all forms will also change?
This is a frightening window into how badly designed your application is. This sort of stuff should be stored in a config file. Christian Graus - Microsoft MVP - C++
-
This is a frightening window into how badly designed your application is. This sort of stuff should be stored in a config file. Christian Graus - Microsoft MVP - C++
I did that because every form need adapter if want to connection to sql. When i drag and drop the adapter and and set sql command, a sqlconnection1 will appear. That's why every form will have sqlconnection1. When i use other pc and copy my application, then i need to change every sqlconnection string in each form. If possible i want to set it once and all sqlconnection1.connectionstring are changed.
-
I did that because every form need adapter if want to connection to sql. When i drag and drop the adapter and and set sql command, a sqlconnection1 will appear. That's why every form will have sqlconnection1. When i use other pc and copy my application, then i need to change every sqlconnection string in each form. If possible i want to set it once and all sqlconnection1.connectionstring are changed.
You can't do that using the "Drag and Drop" controls. It's always been better to write your own SQL connection code. You'll have to replace these connection objects with your own code that reads what the connection string should be from a config file. A better method would be to centralize all your SQL code into a seperate class. Then, each form could use the SQL methods you expose in this class to handle all the data. This is what is meant by the "data tier" in a multiple-tier application. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
I did that because every form need adapter if want to connection to sql. When i drag and drop the adapter and and set sql command, a sqlconnection1 will appear. That's why every form will have sqlconnection1. When i use other pc and copy my application, then i need to change every sqlconnection string in each form. If possible i want to set it once and all sqlconnection1.connectionstring are changed.
Welcome to the world of programming. We tend to write code rather than drag stuff onto a pretty designer. Seriously, the IDE lets you do this, but it's crap. You should have a central class for data access, and ideally a connection object that is reused, or even a pool, depending on the app. Christian Graus - Microsoft MVP - C++
-
You can't do that using the "Drag and Drop" controls. It's always been better to write your own SQL connection code. You'll have to replace these connection objects with your own code that reads what the connection string should be from a config file. A better method would be to centralize all your SQL code into a seperate class. Then, each form could use the SQL methods you expose in this class to handle all the data. This is what is meant by the "data tier" in a multiple-tier application. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Damn - you said the same as I did, but a lot more politely. I need some sleep..... Christian Graus - Microsoft MVP - C++
-
Damn - you said the same as I did, but a lot more politely. I need some sleep..... Christian Graus - Microsoft MVP - C++
:laugh: I was feeling particularly gracious today! It's about 10pm here now, so, that'll end in about 2 hours! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Welcome to the world of programming. We tend to write code rather than drag stuff onto a pretty designer. Seriously, the IDE lets you do this, but it's crap. You should have a central class for data access, and ideally a connection object that is reused, or even a pool, depending on the app. Christian Graus - Microsoft MVP - C++
Im interested when you said using one class to declare sqlconnection. Can you give me example of using it. I know im a beginner in any programming language and only VB.Net is my first programming language and I did using code to declare sql connection but i have difficulty on it and I finally ended up with using sqldataadapter.
-
Im interested when you said using one class to declare sqlconnection. Can you give me example of using it. I know im a beginner in any programming language and only VB.Net is my first programming language and I did using code to declare sql connection but i have difficulty on it and I finally ended up with using sqldataadapter.
If you have a class that contains a private static sqlconnection, and sets it to null, then you can create the connection when it's first used, which is called lazy initialisation ( create it the first time it's used, otherwise return it. ). Use a property to wrap this, and the IDispose/Finaliser pattern to make sure it's cleaned up. Then all your data access code will be in this one class ( which is good design in general ) and therefore all use this one connection. If the app is distributed, then you should use some sort of connection pool if you can, no use having every user hold a connection they are not using. But this pattern works well for local databases with only one user. Here[^] are the MSDN docs on SQLDataAdapter - how did you use it INSTEAD of SQLConnection ? How is the DataAdapter connecting to SQL Server ? It looks to me like this class needs a SQLConnection to work, that's certainly how I use it. Christian Graus - Microsoft MVP - C++