Sunday, November 21, 2010

How to establish connection between VB & SQL Server?

Please tell me how to connect to SQL Server from a VB Application. How to establish connection between VB %26amp; SQL Server?
This is in VB 6. To do it in VB.Net, run it through the code converter.



Replace ';MyServer';, ';MyDatabase';, ';MyUserName';, ';MyPassword';, ';MyTable'; as appropriate:



Dim sConn as String

Dim rs1 as New ADODB.Recordset

Dim cn1 as New ADODB.Connection



' Connection string

' Replace Uid=... onwards with Trusted_Connection=Yes to use Windows security rather than SQL Server

sConn = ';Driver={SQL Server};Server=MyServer;Database=MyDatab鈥?br>


' Open the connection

cn1.Open sConn



' Let's grab something from a table...

rs1.Open ';SELECT * FROM MyTable';, cn1

rs1.CloseHow to establish connection between VB %26amp; SQL Server?
tought to eplain on Y! A!
I think you miss spelled. You mean how to use skillet on BBQ grill.
Start your server and ensure the SQL service is running. On the clients VB Input the IP of the server and also any connection credentials you may need... (you set up the server so i guess you already know these) click connect and away you go. I have had problems like ';TCP connection issue... '; blah blah blah... long and short of it, the firewall needs to allow incoming and outgoing actions. Google is the best place to start for these issues in the future...

No comments:

Post a Comment