Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir
i m tring to connect visual# to sql server but they r not connect probley .
what can i do tell me some code .....
what new way to i access my data in windows form .
Posted
Updated 8-Feb-14 0:27am
v2
Comments
[no name] 8-Feb-14 6:28am    
Not clear..

Try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.

If the connection is not reliable after that, you need to look to your SQL server PC and / or your network for a solution.
 
Share this answer
 
---------configure sql connection string in application page
Imports System.Data.SqlClient
Namespace My

    Partial Friend Class MyApplication

        Const cnstr As String = "Data Source=.;Initial Catalog=dbName;User ID=sa;Password=pwd;"
        Public cn As New SqlConnection(cnstr)

        Private Sub MyApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
            cn.Close()
        End Sub

        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
            Try
                cn.Open()
            Catch derror As SqlClient.SqlException
                MessageBox.Show("Error Occured:" & e.ToString)
            End Try
        End Sub
    End Class

End Namespace
--------use it as follows in .vb page
Dim cmd As New SqlCommand

Public Sub FinMstCodeList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     cmd.Connection = My.Application.cn
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900