| Author |
Topic |
|
tcv56
Starting Member
12 Posts |
Posted - 2007-02-08 : 11:46:19
|
| Hi all,myDB is located atX:\Program Files\Microsoft SQL Server\MSSQL\Data\myDB.mdfand my code is located at : C:\Inetpub\wwwroot\applicationfolderhow do I code my server.mapPath? Thankssub Page_Loaddim 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 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-02-08 : 13:00:48
|
server.mapath is for web server only.use SqlConnection and it's version of connetion string.Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
tcv56
Starting Member
12 Posts |
Posted - 2007-02-08 : 13:54:08
|
| So how do I tell where the db is (X:\Program Files\Microsoft SQL Server\MSSQL\Data\myDB.mdf). My DB is at another server and NOT local where my code is.Sub Page_Load(sender As Object, e As EventArgs) Dim myConnection As SqlConnection Dim myCommand As SqlDataAdapter myConnection = New SqlConnection("server=localhost;" _ & "database=myDB;Trusted_Connection=Yes") myCommand = New SqlDataAdapter("SELECT * FROM Titles", _ myConnection) ' Create and fill a DataSet. Dim ds As Dataset = new DataSet() myCommand.Fill(ds) ' Bind MyRepeater to the DataSet. MyRepeater is the ID of the ' Repeater control in the HTML section of the page. MyRepeater.DataSource = ds MyRepeater.DataBind() End SUb |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-02-08 : 14:21:47
|
server=yourServerInstanceName; Initial Catalog=YourDbName;Go with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-02-08 : 14:23:04
|
| You don't connect to an MDF file from your application. You connect to a server! It doesn't matter that the file is remote. Check out www.connectionstrings.com for more information.Tara Kizer |
 |
|
|
tcv56
Starting Member
12 Posts |
Posted - 2007-02-08 : 14:56:54
|
| so if I connect to Pubs DB at the above server: (x:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf). How do i go about find my server instance name for that pubs db?Can you just show me a real complete example instead of just telling me the concept. If I am an expert I dont have to ask, right? Thanks |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-02-08 : 14:58:52
|
| Stop referring to your database as this: x:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf. That's not how it works for your application. There are examples at the link that I posted. It shows you the proper connection string format for SQL Server.Is your server SQL Server 2000 or SQL Server 2005?Tara Kizer |
 |
|
|
tcv56
Starting Member
12 Posts |
Posted - 2007-02-08 : 15:26:38
|
| sql 2000Is this what you were referring to from your link posted?Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;myServerAddress? how do I find out what my server address is ?Pardon me for my fustration and lack of information. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-02-08 : 15:34:29
|
| Yes that is a valid SQL Server connection string.Since this is sql 2000, you can find out the myServerAddress via:Go to Start..Run..type cmd and hit enter. Type hostname. Note what it says.Go to Start..Run..Control Panel..Administrative Tools..Services. Find the services that start with MSSQL. Is there one that is called MSSQLSERVER. If so, then you just specify what you noted in the previous step with hostname. If instead you find MSSQL$SomeValue, then you need to specify HostnameValue\SomeValue for myServerAddress.Tara Kizer |
 |
|
|
tcv56
Starting Member
12 Posts |
Posted - 2007-02-08 : 15:59:22
|
| thanks,I will give it a try.tcv |
 |
|
|
|