SQL

Работа VB и СУБД (Access, MSSQL, MySQL, Oracle и пр.)
Правила форума
При создании новой темы не забывайте указывать используемую СУБД.
xfolder
Продвинутый пользователь
Продвинутый пользователь
 
Сообщения: 133
Зарегистрирован: 22.07.2002 (Пн) 18:57
Откуда: United Kingdom

SQL

Сообщение xfolder » 10.04.2003 (Чт) 21:35

nikak nemogu naiti primer dlya podklycheniya k microsoft sql server 2000

poskajite pojaluysta esli znaete kak eto sdelat

budu ochen blagodaren

xfolder
Продвинутый пользователь
Продвинутый пользователь
 
Сообщения: 133
Зарегистрирован: 22.07.2002 (Пн) 18:57
Откуда: United Kingdom

Сообщение xfolder » 10.04.2003 (Чт) 22:17

uje nashel

vot

Here is a example to create a ado connection. You could create a basic module and add it to your project and then create a Global ADO connection, so your program will use one connection instance for the whole program. That way once you open up your connection it will stay until you close the connection or exit the program. Make sure in your VB project , you have in your references menu option,Microsoft Activex Dataobjects selected. And also Dcom installed.

In the General/declarations of your basic module declare your connection ..

Global SQLCON As New ADODB.Connection

Then , in your project , say under a command button the code to open your connection, would be ...

Public Sub Command1_Click()
' Connect to SQL server through SQL Server OLE DB Provider.


' Set the ADO connection properties.
SQLCON.ConnectionTimeout = 25 ' Time out for the connection
SQLCON.Provider = "sqloledb" ' OLEDB Provider
SQLCON.Properties("Network Address").Value = "111.111.111.111" ' set the ip address of your sql server
SQLCON.CommandTimeout = 180 ' set timeout for 3 minutes

' Now set your network library to use one of these libraries .. un-rem only the one you want to use !
'SQLCON.Properties("Network Library").Value = "dbmssocn" ' set the network library to use win32 winsock tcp/ip
'SQLCON.Properties("Network Library").Value = "dbnmpntw" ' set the network library to use win32 named pipes
'SQLCON.Properties("Network Library").Value = "dbmsspxn" ' set the network library to use win32 spx/ipx
'SQLCON.Properties("Network Library").Value = "dbmsrpcn" ' set the network library to use win32 multi-protocol

'Now set the SQL server name , and the default data base .. change these for your server !
SQLCON.Properties("Data Source").Value = "MYSERVERNAME"
SQLCON.Properties("Initial Catalog").Value = "MYSQLDATABASE"
SQLCON.CursorLocation = adUseServer ' For ADO cursor location

'Now you need to decide what authorization type you want to use .. WinNT or SQL Server.
'un-rem this line for NT authorization.

'SQLCON.Properties("Integrated Security").Value = "SSPI"

' Or if you want to use SQL authorization , un-rem these 2 lines and supply SQL server login name and password

'SQLCON.Properties("User ID").Value ="SQLUSERNAME"
'SQLCON.Properties("Password").Value = "SQLPASSWORD"

' Now we can open the ADO Connection to SQl server !..
SQLCON.Open


' Now we can do a simple test of the new ADO connection
' Lets return the Time and Date the SQL server thinks it is ..

Dim RS As ADODB.Recordset
Set RS = New ADODB.Recordset
SQLstatement = "SELECT GETDATE() AS SQLDATE " ' Set a Simple Sql query to return the servers time
RS.Open SQLstatement, SQLCON ' Lets open a connection with our new SQLCON connection , and our SQL statement
' Move to first row.
RS.MoveFirst
junk = MsgBox( "Server Time is " & RS("SQLDATE"), vbOKOnly, " SQL SERVER INFO")


End Sub


Вернуться в Базы данных

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 13

    TopList