Monday, March 26, 2012

how to connect to a remote sql DB

Hi all,

myDB is located atX:\Program Files\Microsoft SQL Server\MSSQL\Data\myDB.mdf
and my code is located at : C:\Inetpub\wwwroot\applicationfolder
how do I code my server.mapPath?

Btw, can I get VS 2005 to detect the server path when using server solution.Thanks

sub Page_Load
dim dbconn,sql,dbcomm,dbread
dbconn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("X:\Program Files\Microsoft SQL Server\MSSQL\Data\myDB.mdf"))
dbconn.Open()
sql = "SELECT * FROM myTable"
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
myDB.DataSource = dbread
myDB.DataBind()
dbread.Close()
dbconn.Close()
end sub

One big problem you are pointing to Access database which lets you map the path and SQL Server which controls the path so if your database is Access you can map the path, if it is SQL Server you cannot map the path because the database is not the runtime the relational engine is the runtime. Hope this helps.

No comments:

Post a Comment