Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connection string help

Status
Not open for further replies.

swetham

Programmer
May 5, 2010
257
DE
I am adding the data source using Add datasource wizard. My database is having password and while adding data source i dont want to save the connection string in app.config file and i want to enter it manually in code. How to add the connection string manually and use it for the data source?. I saved the data source without connection string option . Now when i run the code it is showing an error like Access without password(yes).

Can anyone please help me out?

Thank you.
 
In order to properly format the connection string, visit:

Here are examples of setting the connection string in code.
Code:
Public Function Open_Connections() As Boolean
'// Create and open a global session object

   If Not CONN Is Nothing Then
      CONN = Nothing
   End If

   CONN = New SqlClient.SqlConnection

   Try
      With CONN
         ' Trusted Connection.
         .ConnectionString = "Data Source=" & ServerName.Trim & ";Initial Catalog=" & DatabaseName.Trim & ";Integrated Security=SSPI"

         ' Standard Connection (ODBC connection may be required.)
         ' Windows Authentication.
          .ConnectionString = "Data Source=" & ServerName.Trim & ";Initial Catalog=" & DatabaseName.Trim & ";Trusted_Connection=True"
           
         ' Database User.
         .ConnectionString = "Data Source=" & ServerName.Trim & ";Initial Catalog=" & DatabaseName.Trim & ";User ID=" & UserName.Trim & ";Password=" & Password.Trim

         .Open()
      End With
      Open_Connections = True
   Catch ex As Exception
      ex.Message
   End Try

   End Function

If at first you don't succeed, then sky diving wasn't meant for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top