954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

PLZ need help on connecting sql server2008 r2 wid vb.net 2008

im a beginner wid vb .net and need to clear the air wid connecting a database file created on sql server 2008r2 wid vb.net 2008 for a project..plz nebody help from scratch regardng retriving,insertng n modifyng data using vb.net code..awaiting....

Rock_IT
Newbie Poster
1 post since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

You start by reading books. "Wrox Professional Visual Basic" and "Sybex Mastering Visual Basic" both contain very good sections on database programming. Don't expect us to be personal tutors and hold your hand through the learning process.

Reverend Jim
Posting Shark
Moderator
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
 
Begginnerdev
Posting Pro in Training
405 posts since Apr 2010
Reputation Points: 69
Solved Threads: 59
 

hello !
use this code ,

Dim MyConn As New SqlConnection("Data Source=(local);Initial Catalog=dbname;Integrated Security=SSPI;")


Regards

M.Waqas Aslam

waqasaslammmeo
Posting Pro in Training
472 posts since Aug 2011
Reputation Points: 38
Solved Threads: 82
 
im a beginner wid vb .net and need to clear the air wid connecting a database file created on sql server 2008r2 wid vb.net 2008 for a project..plz nebody help from scratch regardng retriving,insertng n modifyng data using vb.net code..awaiting....

u can create a module and call it every time u need a connection

Imports System.Data.SqlClient

Module DBConnection
    Public Connection As SqlConnection = New SqlConnection()
    Public Function Open_DB_Connection() As String
        Try
            Connection.ConnectionString = "Server=.\SQLEXPRESS;" & _
                    "Database=DBName;Trusted_Connection=True"
            Connection.Open()
            Return "Success"
        Catch ex As Exception
            Debug.Print(ex.Message & "in DBConnection_Module")
            Return "Fail"
            Exit Function
        End Try
    End Function

    Public Function Close_DB_Connection() As String
        Try
            Connection.Close()
            Return "Success"
        Catch ex As Exception
            Debug.Print(ex.Message & "in DBConnection_Module")
            Return "Fail"
            Exit Function
        End Try
    End Function
End Module


calling DB connection in ur forms

Dim Open_DB_Con As String
Open_DB_Con = Open_DB_Connection()

--your SQl query part goes here

Dim Close_DB_Con As String
Close_DB_Con = Close_DB_Connection()
poojavb
Posting Whiz
324 posts since Nov 2011
Reputation Points: 31
Solved Threads: 37
 
Imports System.Data.SqlClient
Module ConnectionUsingIP
    Public Con As SqlConnection
    Public cons As String
    Public usertype As String


    Public Sub main()
cons = "Data Source=127.0.0.1,49166;Network Library=DBMSSOCN;Initial Catalog=packwelldata;User ID=sa;Password=bedarsi;Trusted_Connection=False;"
        Con = New SqlConnection(cons)
        Try
            Con.Open()
            'MsgBox("Server Connection is Open ! ")
            Con.Close()
        Catch ex As Exception
            MsgBox("Sorry Can not open connection ! ")

        End Try


    End Sub


End Module
'note:  try enabled your TCP/IP in the sql server configuration manager and restart
princenathan
Newbie Poster
8 posts since Oct 2010
Reputation Points: 8
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You