Dim con As New SqlConnection
con.ConnectionString = "Data Source=.;Initial Catalog=x;Persist Security Info=True;User ID=sa;Password=password"
con.Open()
Now if your not familiar with the format of the connection string, you can get it online or using Visual Studio with these steps.
1. From Visual Studio, Open the Server Explorer by going to menu View > Server Explorer.
2. On Server Explorer, right-click the Data Connections then click "Add Connection".
3. On the Add Connection dialog, Choose Microsoft SQL Server as the data source, Enter the Server name, Select your authentication method and then select or enter the database name.

4. Test the connection by hitting the "Test Connection" button.
5. If connection is successful, click the "Advanced..." to show the Advanced Properties as shown below.

6. The connection string is displayed the bottom field of Advanced Properties dialog box. Copy and Paste it to your code.
7. You can also get the connection string by clicking the Data Connection on the Server Explorer and then look for Connection String property on the Properties window.
For More Coding Tips & Tricks, subscribe now.
0 comments:
Post a Comment