Saturday, February 25, 2012

Changing my database path in web.config

Hey guys,

I uploaded my website from VWD Express to ipower. My database did not work, which I have learned upon some research should have not been a shock to me, but most definetely was. When I contacted tech support they told my that my web.config files were pointing to my local paths. That I should change them and I should be fine. Elsewhere, in the knowledge base I found the strConnect that I am under the impression I need to use.

strConnect = "Provider=SQLOLEDB; Server=SQL-A1; UID=account_username; PWD=account_password; Database=user_db_name"
oSQLServer.Connect strServer,strLogin,strPwd

The problem is, I'm a complete newbie, learning as I go and I can't find anything on where or how I insert this into my web.config to correct my paths. IPower will not help with coding. I know my current connection string is in web.config in the appsettings, that's about as far as my knowledge goes.

So, could anyone show me how I go about putting this into my web.config? Examples are very helpful :]

On a side note, I've been reading that this is a common problem among newbies like myself. So, is changing these files actually going to work, or am I wasting my time? Also, before I get knee-deep into it, is the database-publishing kit put out by MS the way to go here?

Thanks for any and all replies, you guys are always awesome.

your HOST company should have either emailed you or given you information about your database access and login information. you basically change the Server, Username, and password values in your connection string in web.config to match this.

heres a good article about connection strings in web.config .

http://weblogs.asp.net/owscott/archive/2005/08/26/Using-connection-strings-from-web.config-in-ASP.NET-v2.0.aspx

|||

Ok

I know my account id, password, and I think that I can replace. I looked at the article you gave me but, what I'm still confused about is this (what I do have and what the examples in the article look like):

<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"

providerName="System.Data.SqlClient" />

doesn't look anything like this: (what IPower shows me I need to connect my sql database)

strConnect = "Provider=SQLOLEDB; Server=SQL-A1; UID=account_username; PWD=account_password; Database=user_db_name"

oSQLServer.Connect strServer,strLogin,strPwd

Is this strConnect not what I really need? I have no idea what I'm supposed to be doingConfused

|||

the strConnect is the code you would use if it declare your connection in your code and NOT in the web.config file. So everytime you wanted to access the database you would put line of code. By placing the connection in the web.config if you change sqlservers you only need to change it in one location and not every time you make a call to the server. Here is what my web.config file looks like as far as a connection string (using your info above - not sure about the server name).

<connectionStrings>

<clear/>

<addname="MydbConnection"connectionString="Data Source=SQL-A1;Initial Catalog=user_db_name;User ID=account_username;Password=account_password;"providerName="System.Data.SqlClient"/>

</connectionStrings>

then add this code to your project to access the conenction.

Dim dbConnAs SqlConnection =New SqlConnection(ConnectionStrings("MydbConnection").ConnectionString)

then it would be like

dbconn.open()

|||

Thank you very much for trying to help.

strConnect is out the window.

I added the connection string in the web.config

grbourque:

then add this code to your project to access the conenction.

Dim dbConnAs SqlConnection =New SqlConnection(ConnectionStrings("MydbConnection").ConnectionString)

Where? I tried to put that in web.config as well and it didn't want to go there. I tried to put it in the code behind and that didn't work.

I'm sorry I sound like an idiot, I sure feel like one. I have more or less followed some type of tutorial to do everything I've done so far. I'm so frustrated right now that I can't get this to work I can't stand it.

I know your already being very specific and I should be able to pick it up from what you've already told me, but can you tell me where to put the other lines.

|||

Okay a couple things. When you placed the connection string in the web.config file did you keep the same name and only change the user info? If so then the name of that connection string will be MydbConnection. You can actually name it anything you want and have more than one connection if you like, just call up the connection you want by name. Second, I could be completely out to lunch but I do not like the server name they gave you. When I ping that name it comes back as not being able to find it. When I ping the hosted sql server that I am using it comes back with the IP address of that server. So that might be problem #1 and needs to be resolved prior to trying the rest.

Okay as far as the code goes. you would place that where you want to access the database.

private sub GetData()

Dim dbconn as sqlconnection = new sqlconnection(connectionstrings("MydbConnection").ConnectionString)
Dim dbReaderAs SqlDataReader
Dim dbQueryAs String ="SELECT * FROM Table"
Dim dbCommandAs New SqlCommand(dbQuery, dbConn)

dbConn.Open()
dbReader = dbCommand.ExecuteReader()

DO something here with reader

dbconn.close()

End Sub

|||

hi want to just use access db for smaple comments how to use server.mappath in web.config or in tire application classes thanks in advance

No comments:

Post a Comment