Probably s Simple Question but ....

W

Wizard

Hey Group,

Im having some major trouble trying to find info on this one:(

Wonder if somebody could possibly help?

At Present I can get this working:

Private Sub frmSystemOptions_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim RegKeyRead As RegistryKey
'Reset the resulting textbox
txtSQLSRVNAME.Text = ""
'Try to open the given path
RegKeyRead = Registry.CurrentUser.OpenSubKey("Software\Program", True)
If RegKeyRead Is Nothing Then
'If the path doesn't exist, warn the user
MessageBox.Show("key not found!")
Exit Sub
End If
'Retrieve the subkey and its value (alone with a default value if the subkey
is not found)
txtSQLSRVNAME.Text = RegKeyRead.GetValue("CompanyName", "----Not
Found----").ToString
'Close the key
RegKeyRead.Close()
End Sub

Alworks Fine, Show`s in my textbox etc, etc.

Here is my SQL connect sring:

Dim oSQLConn As SqlConnection = New SqlConnection()
oSQLConn.ConnectionString = "Data Source=SQLSRVNAME;" & "Initial
Catalog=myDatabaseName;" & "Integrated Security=SSPI"
oSQLConn.Open()

I would like to build my SQL connect sting so that it looks at the registry
key and uses that as the PC name for the database?

Anybody help me with the code?

Many Thanks
Wizard
 
K

Ken Tucker [MVP]

Hi,

I would do it this way.

Dim conn As SqlConnection

strConn = "Server = " + Environment.MachineName + "\VSdotNet;"

strConn += "Database = NorthWind;"

strConn += "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)



Ken
-----------------
Hey Group,

Im having some major trouble trying to find info on this one:(

Wonder if somebody could possibly help?

At Present I can get this working:

Private Sub frmSystemOptions_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim RegKeyRead As RegistryKey
'Reset the resulting textbox
txtSQLSRVNAME.Text = ""
'Try to open the given path
RegKeyRead = Registry.CurrentUser.OpenSubKey("Software\Program", True)
If RegKeyRead Is Nothing Then
'If the path doesn't exist, warn the user
MessageBox.Show("key not found!")
Exit Sub
End If
'Retrieve the subkey and its value (alone with a default value if the subkey
is not found)
txtSQLSRVNAME.Text = RegKeyRead.GetValue("CompanyName", "----Not
Found----").ToString
'Close the key
RegKeyRead.Close()
End Sub

Alworks Fine, Show`s in my textbox etc, etc.

Here is my SQL connect sring:

Dim oSQLConn As SqlConnection = New SqlConnection()
oSQLConn.ConnectionString = "Data Source=SQLSRVNAME;" & "Initial
Catalog=myDatabaseName;" & "Integrated Security=SSPI"
oSQLConn.Open()

I would like to build my SQL connect sting so that it looks at the registry
key and uses that as the PC name for the database?

Anybody help me with the code?

Many Thanks
Wizard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top