How can I have a user select a local MS SQL database using vb.net? TIA SAL

  • Thread starter Thread starter sal
  • Start date Start date
S

sal

Greets

I have sucessfully created a sql database and vb.net program locally
connecting to my local server.
(I used visual studio 2003)
I would like to send the database along with the compiled vb.net code to
the user. The problem is the users
machine and msde server are going to have different names. How do I change
this in my code to have
the user select thier sql server and sql database located locally on
his/her machine.

PS the user will have msde installed

TIA
 
Hi Sal,

This is a common problem. One way to solve it is to create connections
based on some form of config file(s), so that the client machine has to
server name, user name, etc that is appropriate for his environment. Here's
an example of how I do it:
Dim sr As StreamReader = New StreamReader("f:\imcapps\config\config.txt")

globalconnectionstring = sr.ReadLine()

Dim srx As StreamReader = New StreamReader("f:\imcapps\config\configx.txt")

globalconnectionstringx = srx.ReadLine()

Dim srp As StreamReader = New StreamReader("f:\imcapps\config\configp.txt")

globalpwd = srp.ReadLine()

Dim srs As StreamReader = New StreamReader("f:\imcapps\config\configs.txt")

globalservername = srs.ReadLine()

Dim sru As StreamReader = New StreamReader("f:\imcapps\config\configu.txt")

globalusername = sru.ReadLine()

Dim srmso As StreamReader = New
StreamReader("f:\imcapps\config\msopath.txt")

globalmsopath = srmso.ReadLine()



Dim oconn As New SqlConnection(globalconnectionstring)

This reads all of the config files (.txt files in my environment) and
absorbs them into globalconnectionstring, globalusername, etc and then makes
the connection.

There are more secure ways to do this - through the registry, for example,
but you get the idea.

HTH,

Bernie Yaeger
 
Hi,

Rule is simple - never hardcode server name , database name and user
information into application. What you could do is to create login form to
ask user to put this information and build your connection string
dynamically. Then you could store database and server name in a settings
file or in a registry, so next time, when user runs application, you could
read these values and prepopulate this information in a login screen
 
Sal,

For the connectionstring it is easy, you can set those in the first event
that takes place in your program. By instance the load event of your startup
form. (And do not delete the ones which are created using the designer when
you did that in that way, that gives problems afterwards while updating your
program).

For the datatables I know only the solutions of creating them using the
command.executenonquery and SQL statetements with "Create Table etc) or with
a SQL script.

The firs approach is in my opinion efficient with a single user situation,
than you can do in a special installation section, where you than as well
set directly your connection string in the registry.

In the script approach I would set the connection string in a config.file.

Just my thought?

Cor
 
Back
Top