数据库连接 [英] Database 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 ;持久安全信息=假;用户
ID = ef;密码= ef;初始目录=爵士;数据源= D:\Program Files \ Microsoft /
SQL Server \ MSSQL \Data\jazz_data.mdf"
query =" Select * from Login where login =''" &安培; txt_uid.Text& "''
和密码=''" &安培; txt_pswd.Text& "'';"
cn =新OleDbConnection(str)
cmd =新OleDbCommand(查询,cn)
cn.Open ()
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()
推荐答案
一些观察结果。您正在使用SQL Server数据提供程序
(SQLOLEDB)和通用OleDbConnection。 SQLConnection类是专门为SQL Server设计的
,通常会提供更好的b / b
性能。其次,通常,连接的数据源属性
字符串是指SQL Server实例而不是.mdf文件。
-
David Lloyd
MCSD .NET
http://LemingtonConsulting.com
此响应按原样提供。没有任何陈述或保证。
" Ef Dublio" < Ef中****** @ discussions.microsoft.com>在消息中写道
新闻:8A ********************************** @ microsof t.com ...
我正在编写以下代码,但它说无效连接
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& "''
和密码=''" &安培; txt_pswd.Text& "'';"
cn =新OleDbConnection(str)
cmd =新OleDbCommand(查询,cn)
cn.Open ()
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.
"Ef Dublio" <Ef******@discussions.microsoft.com> wrote in message
news:8A**********************************@microsof t.com...
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()
这篇关于数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!