Unable to connect to SQL Server 2014 via sConnString
Trying to connect to a SQL Server 2014 and receive the error : (System.Data.OleDb.OleDbException: '[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.')
I'm not sure what is wrong with the code below.
This is my code:
' Set connection to the database
Dim oOleDbConnection As OleDbConnection = Nothing 'Create db connection
Dim objCmd As OleDbCommand = Nothing
Dim sConnString As String, strSQL As String, strSQLSelect As String
'Connection string for database
sConnString = "Provider=SQLOLEDB;Server=RICKNDELLM2800\SQLEXPRESS;Database=ExactMAXSAM;User ID=sa;Password=M@x@dm1n;"
oOleDbConnection = New OleDbConnection(sConnString)
oOleDbConnection.ConnectionString = sConnString
oOleDbConnection.Open()
frmimport.Show() 'to display subform
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
1 answer
try
Dim Adocon As ADODB.Connection 'for SQL server Database
Public Function newRecordset(SqlStatement As String) As ADODB.Recordset
On Error GoTo MSDB
Set Adocon = New ADODB.Connection
Set newRecordset = New ADODB.Recordset
Dim strCNString As String
With Adocon
.Provider = "SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=database"
.Open
End With
newRecordset.CursorLocation = adUseClient
newRecordset.Open SqlStatement, Adocon, adOpenDynamic, adLockOptimistic
End Function