Question connect to LAN Server

Bhutanesedude

New member
Joined
Jun 12, 2013
Messages
4
Programming Experience
Beginner
Dear Experts,

Please help me to connect a Frontend to a Backend which is on a LAN Server. I am using this DBAccess Code to connect the Frontend and Backend on standalone application.
------------------------------------------
Public Class DBAccess
Shared cs As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=" & Application.StartupPath.Replace("\bin\Debug", "") & "\ims.mdf;Integrated Security=True;User Instance=True")
Public Shared Function SaveData(ByVal qry As String) As Boolean


Dim cmd As New SqlCommand(qry, cs)


Try
cs.Open()
cmd.ExecuteNonQuery()
Return True
Catch ex As Exception
Return False
Finally
cs.Close()
End Try
End Function
------------------------------------------------------------------
Now I want that same project to run on LAN Server basis where the front end will be installed on Client PC and Central database will be on LAN Server.

Please help me.

Thank you
 
First of all, that's a bad connection string. I suggest that you follow the CodeBank link in my signature to learn how to manage local data files. In short, you should add your data file to the project and then let it copy the file to the output folder. You then use |DataDirectory| in the connection string to refer to the folder path, e.g.
Shared cs As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ims.mdf;Integrated Security=True;User Instance=True")
It's generally not a good idea to hard code the connection string in your application either, because it means that you'll never be able to change the connection string without recompiling the app.

In regards to your question, do you still want to use the MDF file deployed with your app as the database or is there an existing database attached to your network instance of SQL Server? If it's the former then you're out of luck, because a local data file requires a local SQL Server Express instance. If it's the latter then you need to remove the AttachDbFilename attribute and add the Data Source and Initial Catalog attributes. See www.connectionstrings.com for all your connection string needs.
 
Dear jimcilhinney,

Thank you, it was clear and understandable. If I am share you my environment, I have a server with Windows Server 2k8 R2 installed with SQL 2k8. I have never developed an application using a Server Database, therefore, since now I am learning, I am thinking to implement an Application with Back end on Server on LAN.

So please help me, on how to configure or structure the Tables and Database in SQL Server 2k8 and in same, how can I connect the same to Front End on Client PC (VB.NET Application). Going through Google through give me a syntax but I really need to learn therefore if you experts can spare few moments on this.

Also please help me to start MSSQL in my Server. When I try to start it, it comes with Error. I have the screenshot here. Starting Error.PNG

Thank you.
 
Last edited:
Database design and issues running SQL Server are beyond the scope of this forum. That said, the error message you posted explicitly instructs you to consult various logs for details of the issue. Have you done that? I'll wager not.

As for how to work with databases in your application, you might try following the Data Walkthroughs link in my signature.
 
Back
Top