如何查找连接字符串? [英] How Do I Find The Connection String?
问题描述
我有一个程序可以在加载时创建数据库,但是我发现的每个资源都没有告诉我一个关键问题。如何连接到该数据库?我用来创建数据库的资源是使用VB.NET以编程方式创建Microsoft Access数据库 [ ^ ]
这是一个很好的资源,但没有告诉我如何连接和编辑它。在此之前,我有一个外部数据库,我将使用类似于以下代码进行连接和编辑:
I have a program that creates a database on loadup, but every resource I've found has failed to tell me a crucial question. How do I connect to that database? The resource I used to create the database was Create Microsoft Access Database Programmatically using VB.NET[^]
A great resource but doesn't tell me how to connect and edit it. Before this I had an external database and I would connect and edit using code similar to:
Dim strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
System.Environment.CurrentDirectory & "\EV Tracker.mdb"
DbConnection = New OleDbConnection(strConnectionString)
Try
' Open connection
DbConnection.Open()
'Create the SQL Query that draws out the data
Dim SqlQry As String = "SELECT * FROM PokemonTable WHERE Pokemon = '" & PokeTeam.SelectedItem & "'"
'create data adapter
Dim da As OleDbDataAdapter = New OleDbDataAdapter(SqlQry, DbConnection)
'create dataset
Dim ds As DataSet = New DataSet
'fill dataset
da.Fill(ds, "PokemonTable")
'get data table
Dim dt As DataTable = ds.Tables("PokemonTable")
'display data
Dim row As DataRow
For Each row In dt.Rows
HPAmount.Value = row("HPValue")
AtkAmount.Value = row("AtkValue")
DefAmount.Value = row("DefValue")
SpAtkAmount.Value = row("SpAtkValue")
SpDefAmount.Value = row("SpDefValue")
SpdAmount.Value = row("SpdValue")
Next row
Catch ex As OleDbException
MsgBox("Error: " & ex.ToString & vbCrLf)
Finally
' Close connection
DbConnection.Close()
End Try
但是由于显而易见的原因,这不再是正确的连接字符串。这整个事情是否有所不同,或者我只是需要找到正确的连接字符串?
But for obvious reasons, that's no longer the correct connection string. Does this whole thing work differently or do I just need to find the right connection string?
推荐答案
这是完全相同的 - 你只需删除 System.Environment.CurrentDirectory& \ EV Tracker.mdb
part并将其替换为您加载应用时创建的数据库的完整路径。
It's exactly the same thing - you just have to remove the System.Environment.CurrentDirectory & "\EV Tracker.mdb"
part and replace it with the full path to the database you created when your app loaded.
这篇关于如何查找连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!