Database Connection

G

Guest

I am writing the following code, but it say invalid connection

Dim str As String
Dim query As String
Dim cmd As OleDbCommand
Dim cn As OleDbConnection
Dim dr As OleDbDataReader



str = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=ef;Password=ef;Initial Catalog=jazz;Data Source=D:\Program Files\Microsoft
SQL Server\MSSQL\Data\jazz_data.mdf"
query = "Select * from Login where login = '" & txt_uid.Text & "'
and password = '" & txt_pswd.Text & "';"
cn = New OleDbConnection(str)
cmd = New OleDbCommand(query, cn)
cn.Open()
 
D

David Lloyd

A couple of observations. Your are using an SQL Server data provider
(SQLOLEDB) and a generic OleDbConnection. The SQLConnection class is
designed specifically for SQL Server and will generally provide better
performance. Second, generally, the Data Source property of the connection
string refers to the SQL Server instance rather than the .mdf file.


--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I am writing the following code, but it say invalid connection

Dim str As String
Dim query As String
Dim cmd As OleDbCommand
Dim cn As OleDbConnection
Dim dr As OleDbDataReader



str = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=ef;Password=ef;Initial Catalog=jazz;Data Source=D:\Program
Files\Microsoft
SQL Server\MSSQL\Data\jazz_data.mdf"
query = "Select * from Login where login = '" & txt_uid.Text & "'
and password = '" & txt_pswd.Text & "';"
cn = New OleDbConnection(str)
cmd = New OleDbCommand(query, cn)
cn.Open()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top