Newbie question ob vb.net and connecting to a dB

  • Thread starter Thread starter RichK
  • Start date Start date
R

RichK

Hello All!

Working on my first "production" program and need a hand.....

I have written a program that is supposed to access a SQL database and then
run a crystal report or do other things depending on which button is
pressed. I have this program running well on my design setup but when I run
it on another PC I get errors . It runs perfectly when I run it on the PC I
designed it on.

My first guess is that when I run it on another PC I need a way to connect
to the Database I want to use. Is there a way I can specify where the
program should look for the Database or a way I can have an input box where
the database to be used can be specified.

Thanks in advance for any help you can provide this newbie :)

eCaVeMaN
 
I do the same kind of development. Here is what you need on your client
machine:

An ODBC Connector to the SQL Server Database

In your code you need to specify the ODBC Connection somehow ...
something like this might work:
myquery.Connect = "ODBC;DSN=dBName;

Hope it Helps

Randy
 
Better of using the SQL Server Specific objects if you can. They will run alot faster than the ODBC. The trick to connect is your connection string. Make sure the Data Source is pointing to the machine and the named Instance (if there is one) of SQL Server you are using. On your own machine, it was probably just defaulting to local

Dim m_strConnectionString as String ' Connect Strin
Dim m_SQLCN as SqlClient.SqlConnection ' ADO.NET Connection for SQL Serve
Dim m_SQLDataAdapter as SqlClient.SqlDataAdapter ' Used to fill Dataset

m_strConnectionString = "Data Source = YourServer\YourInstance;"
& "Initial Catalog = YourCatalog;User Id = CatalogOwner;"
& "Password = YourPassword;

' Create a Dataset instanc
m_DataSet = New DataSe

' Catch any SQl Exception
Tr
' Create a new instance of SQLConnectio
m_SQLCN = New SqlClient.SqlConnection(m_strConnectionString

m_SQLCN.Open()

' Create a SQL Command Object to execute Transact-SQL Staement
m_SQLCommand = New SqlClient.SqlComman
m_SQLCommand.Connection = m_SQLC

' Create an instance of the data adapte
m_SQLDataAdapter = New SqlClient.SqlDataAdapte

' Handle SQL Exception
Catch e As SqlClient.SqlExceptio
' Pop a error messag
MsgBox(e.Errors(0).ToString & "\nUnable to Establish Connection to SQL Database",
MsgBoxStyle.Critical, "Error Connection to Database"
End Try
 
Back
Top