Showing posts with label path. Show all posts
Showing posts with label path. Show all posts

Sunday, March 25, 2012

Changing the default database files path fails

i have the following code segment which works fine as is:

try

{

ServerConnection connection = new ServerConnection("localhost");

Server server = new Server(connection);

if (!server.Databases.Contains("SMO_TEST"))

{

Database database = new Database(server, "SMO_TEST");

//FileGroup fileGroup = new FileGroup(database, "PRIMARY");

//database.FileGroups.Add(fileGroup);

//DataFile dataFile = new DataFile(fileGroup, "SMO_TEST_Data");

//dataFile.FileName = "D:\\SMO_TEST_Data.mdf";

//fileGroup.Files.Add(dataFile);

//LogFile logFile = new LogFile(database, "SMO_TEST_Log");

//logFile.FileName = "D:\\SMO_TEST_Log.ldf";

//database.LogFiles.Add(logFile);

database.Create();

}

}

catch (FailedOperationException ex)

{

Console.WriteLine(ex.Message);

}

when i uncomment the lines commented above it fails.

Any help?

Fails with which error ?

Jens K. Suessmeyer

http://www.sqlserver2005.de
|||

hi Jenz

thanks for your reply. the code posted earlier worked smoothly just after a computer restart.the error message was either

"Create failed for Database 'SMO_TEST'." or "Drop failed for Database 'SMO_TEST'." with whatever mistake i made, which provided no help in correcting the problem.

however another issue arised when i tried to use a transaction using either method connection.BeginTransaction(); or server.ConnectionContext.BeginTransaction();

(1) how to correct this problem? and

(2) what kind of transaction occures here? is it a distributed transaction?

also i would like to ask

(3)if there is any way to diable full text indexing other than using

connection.ExecuteNonQuery(databaseName + ".dbo.sp_fulltext_database @.action = 'disable'");?(see the code below) .

sql server management studio creates the database with full text indexing disabled by default. but when using smo it is enabled by default and the documentation claims the opposite.

(4) so where does smo take its default values from?

string sqlServerInstance = "localhost";

string databaseName = "SMO_TEST";

string dataFileLogicalName = databaseName + "_Data";

string logFileLogicalName = databaseName + "_Log";

string dataFilePhysicalName = dataFileLogicalName + ".mdf";

string logFilePhysicalName = logFileLogicalName + ".ldf";

string dataFilePath = "D:\\TEST_DIR\\";

string logFilePath = "D:\\TEST_DIR\\";

if (!Directory.Exists(dataFilePath))

{

Directory.CreateDirectory(dataFilePath);

//throw new DirectoryNotFoundException("The data file directory " + dataFilePath + " does not exists.");

}

if (!Directory.Exists(logFilePath))

{

Directory.CreateDirectory(logFilePath);

//throw new DirectoryNotFoundException("The log file directory " + logFilePath + " does not exists.");

}

string defaultFileGroupName = "PRIMARY";

ServerConnection connection;

connection = new ServerConnection(sqlServerInstance);

Server server = new Server(connection);

try

{

//connection.BeginTransaction();

server.ConnectionContext.BeginTransaction();

if (server.Databases.Contains(databaseName))

{

server.Databases[databaseName].Drop();

server.Alter();

}

Database database = new Database(server, databaseName);

FileGroup fileGroup = new FileGroup(database, defaultFileGroupName);

database.FileGroups.Add(fileGroup);

DataFile dataFile = new DataFile(fileGroup, dataFileLogicalName);

dataFile.FileName = dataFilePath + dataFilePhysicalName;

dataFile.GrowthType = FileGrowthType.KB;

dataFile.Growth = 1024d;

fileGroup.Files.Add(dataFile);

LogFile logFile = new LogFile(database, logFileLogicalName);

logFile.FileName = logFilePath + logFilePhysicalName;

logFile.GrowthType = FileGrowthType.Percent;

logFile.MaxSize = 2147483648d;

database.LogFiles.Add(logFile);

database.Create();

// disable full text indexing

connection.ExecuteNonQuery(databaseName + ".dbo.sp_fulltext_database @.action = 'disable'");

//connection.CommitTransaction();

server.ConnectionContext.CommitTransaction();

}

catch (FailedOperationException ex)

{

//connection.RollBackTransaction();

server.ConnectionContext.RollBackTransaction();

Console.WriteLine(ex.Message);

}

finally

{

if (connection != null)

{

if (connection.IsOpen)

{

connection.Disconnect();

}

connection = null;

}

}

thanks again

|||<P align=left><FONT face=Arial size=2>1) Some commands cannot be used within a transaction, but the problem in your case is that the database seems to be in use during the dropping action, see the blog post on my site for more information about that:<BR><BR>2) local one<BR><BR>3) DId not see anything for that, SMO tell that this functionality is deprecated in further versions.</FONT></P>
<P align=left>&nbsp;</P>
<P align=left>4) Which values do you mean ? Some are coded in the SMO library, some are taken from the db system.</P>
<P dir=ltr style="MARGIN-RIGHT: 0px" align=left><BR><BR>Jens K. Suessmeyer<BR><BR><BR><A href="http://www.sqlserver2005.de">http://www.sqlserver2005.de</A><BR></P>|||

Waleed,

You need to add the data and log files before you can assign the filename properties. Try the code here (I've adjusted your code):

try
{
ServerConnection connection = new ServerConnection("localhost");
Server server = new Server(connection);

if (!server.Databases.Contains("SMO_TEST"))
{

Database database = new Database(server, "SMO_TEST");

FileGroup fileGroup = new FileGroup(database, "PRIMARY");
database.FileGroups.Add(fileGroup);
DataFile dataFile = new DataFile(fileGroup, "SMO_TEST_Data");
fileGroup.Files.Add(dataFile);
dataFile.FileName = "D:\\SMO_TEST_Data.mdf";
LogFile logFile = new LogFile(database, "SMO_TEST_Log");
database.LogFiles.Add(logFile);
logFile.FileName = "D:\\SMO_TEST_Log.ldf";
database.Create();
}
}
catch (FailedOperationException ex)
{
Console.WriteLine(ex.Message);
}

|||

dear MVPs,

I tried to loop through the inner exception of the failedOperationException and it turned out that the problem is that Database.Create(), Database.Drop() and

connection.ExecuteNonQuery(databaseName + ".dbo.sp_fulltext_database @.action = 'disable'");

cannot be contained in a transaction

this answers my question about transactions

thank you very much

Monday, March 19, 2012

Changing SQL Server Management Studio "My Projects" path

Hi,

I want to change the default "My Projects" save location from "My Documents\SQL Server Management Studio\Projects" to somewhere else. I didn't see the My Projects path in the SQL Server Management Studio Options.

How can I change the path?

Thanks,

Mike

One way is to use Regedit, and search for 'SQL Server Management Studio\Projects'.

You will find the location for NewProjects, DefaultProjects, NewProjItems, DefaultProjItems -and a few other things you might like to know about.

As always, with editing the registry, use caution.

|||I have the same question/issue. I've looked for a registry entry like 'SQL Server Management Studio\Projects' but have not been able to locate anything that even comes close. Running under Windows Vista Enterprise. Can you give the full path to the registry key? TIA|||

On my computer, Windows Server 2003, I found it in two locations:

HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\90\Tools\Shell

AND

HKEY_USERS\{My SID}\Software\Microsoft\Microsoft SQL Server\90\Tools\Shell

The values to find and change are:

DefaultNewProjectLocation

MyDocumentsLocation

Both need to be 'Expandable String Value' data

Again, the RegEdit search was for: [SQL Server Management Studio\Projects]

(no square brackets)

|||For SQL Server Express the location within the registry is:

HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM

and the search item to use is:

"SQL Server Management Studio Express\Projects"

Changing SQL Server Management Studio "My Projects" path

Hi,

I want to change the default "My Projects" save location from "My Documents\SQL Server Management Studio\Projects" to somewhere else. I didn't see the My Projects path in the SQL Server Management Studio Options.

How can I change the path?

Thanks,

Mike

One way is to use Regedit, and search for 'SQL Server Management Studio\Projects'.

You will find the location for NewProjects, DefaultProjects, NewProjItems, DefaultProjItems -and a few other things you might like to know about.

As always, with editing the registry, use caution.

|||I have the same question/issue. I've looked for a registry entry like 'SQL Server Management Studio\Projects' but have not been able to locate anything that even comes close. Running under Windows Vista Enterprise. Can you give the full path to the registry key? TIA|||

On my computer, Windows Server 2003, I found it in two locations:

HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\90\Tools\Shell

AND

HKEY_USERS\{My SID}\Software\Microsoft\Microsoft SQL Server\90\Tools\Shell

The values to find and change are:

DefaultNewProjectLocation

MyDocumentsLocation

Both need to be 'Expandable String Value' data

Again, the RegEdit search was for: [SQL Server Management Studio\Projects]

(no square brackets)

changing source path

Hello,

I moved my Report source files from C:\Documents and Settings\username\My Documents\ to C:\Inetpub\wwwroot\Apps\Src it seems my Data Source does not work. I am able to open reports but could not connect database. Is there anywhere else I need to redefine the path.

Thanks,

I am not sure what you are doing - BUT - never put your source code in inetpub <wwwroot> and on top of it the directory is probably shared!!!!!!

You are missing the entire point of the deployment mechanism of any web service and most importantly Reporting Services!

Please slow down a little with all due respect! And I do mean with ALL DUE RESPECT!

Put your source code in a secure directory - open a new project in Visual Studio change the data source in your project

Chane the Project Properties to point to your server and ensure the data sources within your project point to the same...

Data Source=YOUR SERVER NAME;Initial Catalog=YOUR DATA BASE NAME

REmove your source code from inetpub!@.!!!!!

Deploy (which does a build) to your server -- protect your source code!

Best REgards,

|||

Hi Josun,

Thank you very much for the advice. I will try to move it somewhere else. However I think the problem is not because of inetpub. Do you have any idea why I am getting that problem when I move all the files from one server to another even though with same path.

|||

Well - Maybe

Please excue my "LEO ( Thai Beer induced state )

What is going on? Why so much wory about ----

I will go back and read your original post!

Something is a-miss here!

Wednesday, March 7, 2012

Changing path of web service?

I have 2 report services servers one for development and one for live, I
need to add a reference to the web service in my app, but during development
it has to refernce development server, during deployment it has to reference
what ever the end user calls their server, can you change the reference url
of a web service at run time? if so how? thanks! the web services will all
have the same definition at all times. I'm also doing this in VB.NETSmokey Grindle wrote:
> I have 2 report services servers one for development and one for live, I
> need to add a reference to the web service in my app, but during development
> it has to refernce development server, during deployment it has to reference
> what ever the end user calls their server, can you change the reference url
> of a web service at run time? if so how? thanks! the web services will all
> have the same definition at all times. I'm also doing this in VB.NET
IIRC, when you declare an instance of the web service, you can set it's
URL property to the correct one.

Changing path of data & log files on the fly

We have a SQL Server setup as a publisher to 15 subscribers. We need to change the path of the data & log files to a new drive (added a new harddisk). We plan to take a cold backup of the database and shift the data & log files to the new drive. Then we just attach the data & log files from the new path.

Will this disturb my existing replication Setup?
Is the the correct procedure for changing the path of the existing data & log files?
What is the appropriate method for shifting data & log file of a live database to a different location (directory/drive) ?

thanks in advancedisable replication;
sp_detach_db;
move files to new location;
sp_attach_db;
enable replication.|||Thanks for the suggestion. I'll try this out and confirm back. Thanks again anyways.

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

Friday, February 24, 2012

changing mapping

I read in my record. As we proceed down the pipeline, I want to put kind of record (with length 742) into one path, and a different kind of record (with length 242) into a different path. My problem is that I have (obviously) different fixed width column mappings for the two kinds of records. How can I change the column mapping mid-stream? Can I? Do I need to just write out to flat files and go from there?

Thanks!

Jim Work
Yes, you have two options. Move each "path" to new, separate flat files (or database tables, or even RAW files) and then use the new files (or whatever chosen) in a new set of data flows to process the records.

The other option is once the record layouts have been split on their own paths is to use a derived column transformation to substring the data into the correct columns.|||Thanks a bunch!

Tuesday, February 14, 2012

Changing directory where database files are stored

Hi

After install the mdf and log files are stored in the Program Files directory tree.

How do I change the place were they are stored to a path of my own choice, so that new DBs get created there too?

I've looked though the docs, but I can't find this.

Thanks

John

You cna change this using Management Studio Express in the Server Properties dialog.

Mike

Sunday, February 12, 2012

Changing database path of my reports

hi!!!
i have problem in changing the database of my reports. i found a code here

Dim crxDatabaseTable As CRAXDRT.DatabaseTable
For Each crxDatabaseTable In report.Database.Tables
crxDatabaseTable.ConnectionProperties.Item("Database Name") = "C:\Temp\xtreme.mdb"
Next crxDatabaseTable

bu when i coded this to my project it says CRAXDRT.DatabaseTable

anyone can help me for this i have change paths with code because of when i run my project any drives it has to work...Why not use
crxDatabaseTable.Location = "C:\Temp\xtreme.mdb"
instead of setting ConnectionProperties?

Also, dont forget that a report can have subreports that will also need setting location info.|||how can i use it?

i cant do anything... i think i have to define something but i dont know what...

my report name is exitreportrep when i wrote it to a form load or anywhere i have 3 choice only
exitreportrep.EnableEventLog()
exitreportrep.Equals()
exitreportrep.ReferenceEquals()

i dont know what to do...

Changing database Path at runtime

Hi,
Plz help me.
I have created a report with MS Access, "C:\House\house.mdb"
I want to change database path at runtime to "D:\program files\House\house.mdb".
How can i make it possible? i am not using DSN, am writing direct code to open database.

Advanced Thanks.

bye,
kandula.Try this...

report.database.tables.item(integer).setdatasource dataenvironment(command)

Example,

Report1.Database.Tables.Item(1).SetDataSource DataEnvironment1.rsCommand2