Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I can see a few problems.</p> <ol> <li>You are using concatenation in a SQL statement. This is a bad practice. Use a parameterized query instead.</li> <li>You are surrounding the password with single quotes. They are not needed and in fact, I'm surprised it even works assuming the password itself does not have single quotes.</li> <li>You should surround classes that implement IDisposable with a Using block</li> <li>You should recreate the WASP connection object in GetWASPcr like so:</li> </ol> <pre><code>Public Sub GetWASPAcr() Dim username As String = HttpContext.Current.User.Identity.Name Dim listOfDatabaseConnectionString As String = "..." Using listOfDatabaseConnection As SqlConnection( listOfDatabaseConnectionString ) Using cmd As New SqlCommand("SELECT WASPDatabase FROM dbo.aspnet_Users WHERE UserName = @Username") cmd.Parameters.AddWithValue( "@Username", username ) Dim dt As New DataTable() Using da As New SqlDataAdapter( cmd ) da.Fill( dt ) If dt.Rows.Count = 0 Then WaspConnection = Null Else Dim connString As String = String.Format("Data Source=JURA;Initial Catalog={0};User Id={1};Password={2};" _ , dt.Rows(0)("WASPDatabase") _ , ConfigurationManager.AppSettings("WASPDBUserName") _ , ConfigurationManager.AppSettings("WASPDBPassword")) WaspConnection = New SqlConnection(connString); End If End Using End Using End Using End Sub </code></pre> <p>In this example, <code>listOfDatabaseConnectionString</code> is the initial connection string to the central database where it can find the catalog name that should be used for subsequent connections.</p> <p>All that said, why would you need a class level variable to hold a connection? You should make all your database calls open a connection, do a sql statement, close the connection. So, five database calls would open and close a connection five times. This sounds expensive except that .NET gives you connection pooling so when you finish with a connection and another is requested to be opened, it will pull it from the pool.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload