Click here to Skip to main content
15,893,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to connect sql database server to vb.net?
Posted

You can hardcode it like this
VB
var connection = New System.Data.SqlClient.SqlConnection(connectionString)
connection.Open()

or you can do it more independently
VB
var factory = System.Data.Common.DbProviderFactories.GetFactory(providerString)
var connection = factory.CreateConnection()
connection.ConnectionString = connectionString
connection.Open()


There is lots of info out there, and then I have an article on connecting to databases without hardcoding your provider here.
 
Share this answer
 
Paste this code in connection Module then and get connection anywhere in project.

where you need connection simple you

call below function like that.
conn1=GetConnectIcSoft

then

conn1.open()

VB
Public Conn1 As SqlConnection
Public Function GetConnectIcSoft()
Conn1 = New SqlConnection(Data Source=SERVERNAME; Initial Catalog= DATABASE_NAME; User Id=sa; Password=YOUR_SQL_PASSWORD;Integrated Security = True;MultipleActiveResultSets=True;)
Return conn1
End Function
 
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